@@ -50,6 +50,7 @@ public class RustGenerator implements CodeGenerator
50
50
{
51
51
static final String WRITE_BUF_TYPE = "WriteBuf" ;
52
52
static final String READ_BUF_TYPE = "ReadBuf" ;
53
+ static final String ANONYMOUS_LIFETIME = "'_" ;
53
54
static final String BUF_LIFETIME = "'a" ;
54
55
55
56
enum CodecType
@@ -187,9 +188,19 @@ String schemaVersionType()
187
188
return rustTypeName (ir .headerStructure ().schemaVersionType ());
188
189
}
189
190
190
- static String withLifetime (final String typeName )
191
+ static String withAnonymousLifetime (final String typeName )
191
192
{
192
- return format ("%s<%s>" , typeName , BUF_LIFETIME );
193
+ return withLifetime (typeName , ANONYMOUS_LIFETIME );
194
+ }
195
+
196
+ static String withBufLifetime (final String typeName )
197
+ {
198
+ return withLifetime (typeName , BUF_LIFETIME );
199
+ }
200
+
201
+ private static String withLifetime (final String typeName , final String lifetime )
202
+ {
203
+ return format ("%s<%s>" , typeName , lifetime );
193
204
}
194
205
195
206
static void appendImplWithLifetimeHeader (
@@ -1243,14 +1254,14 @@ static void appendImplEncoderTrait(
1243
1254
final Appendable out ,
1244
1255
final String typeName ) throws IOException
1245
1256
{
1246
- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Writer" ), withLifetime (typeName ));
1257
+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Writer" ), withBufLifetime (typeName ));
1247
1258
indent (out , 2 , "#[inline]\n " );
1248
1259
indent (out , 2 , "fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {\n " );
1249
1260
indent (out , 3 , "&mut self.buf\n " );
1250
1261
indent (out , 2 , "}\n " );
1251
1262
indent (out , 1 , "}\n \n " );
1252
1263
1253
- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Encoder" ), withLifetime (typeName ));
1264
+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Encoder" ), withBufLifetime (typeName ));
1254
1265
indent (out , 2 , "#[inline]\n " );
1255
1266
indent (out , 2 , "fn get_limit(&self) -> usize {\n " );
1256
1267
indent (out , 3 , "self.limit\n " );
@@ -1268,21 +1279,21 @@ static void appendImplDecoderTrait(
1268
1279
final Appendable out ,
1269
1280
final String typeName ) throws IOException
1270
1281
{
1271
- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , "ActingVersion" , withLifetime (typeName ));
1282
+ indent (out , 1 , "impl %s for %s {\n " , "ActingVersion" , withAnonymousLifetime (typeName ));
1272
1283
indent (out , 2 , "#[inline]\n " );
1273
1284
indent (out , 2 , "fn acting_version(&self) -> %s {\n " , schemaVersionType );
1274
1285
indent (out , 3 , "self.acting_version\n " );
1275
1286
indent (out , 2 , "}\n " );
1276
1287
indent (out , 1 , "}\n \n " );
1277
1288
1278
- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Reader" ), withLifetime (typeName ));
1289
+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Reader" ), withBufLifetime (typeName ));
1279
1290
indent (out , 2 , "#[inline]\n " );
1280
1291
indent (out , 2 , "fn get_buf(&self) -> &ReadBuf<'a> {\n " );
1281
1292
indent (out , 3 , "&self.buf\n " );
1282
1293
indent (out , 2 , "}\n " );
1283
1294
indent (out , 1 , "}\n \n " );
1284
1295
1285
- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Decoder" ), withLifetime (typeName ));
1296
+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Decoder" ), withBufLifetime (typeName ));
1286
1297
indent (out , 2 , "#[inline]\n " );
1287
1298
indent (out , 2 , "fn get_limit(&self) -> usize {\n " );
1288
1299
indent (out , 3 , "self.limit\n " );
0 commit comments