@@ -50,6 +50,7 @@ public class RustGenerator implements CodeGenerator
5050{
5151 static final String WRITE_BUF_TYPE = "WriteBuf" ;
5252 static final String READ_BUF_TYPE = "ReadBuf" ;
53+ static final String ANONYMOUS_LIFETIME = "'_" ;
5354 static final String BUF_LIFETIME = "'a" ;
5455
5556 enum CodecType
@@ -187,9 +188,19 @@ String schemaVersionType()
187188 return rustTypeName (ir .headerStructure ().schemaVersionType ());
188189 }
189190
190- static String withLifetime (final String typeName )
191+ static String withAnonymousLifetime (final String typeName )
191192 {
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 );
193204 }
194205
195206 static void appendImplWithLifetimeHeader (
@@ -1243,14 +1254,14 @@ static void appendImplEncoderTrait(
12431254 final Appendable out ,
12441255 final String typeName ) throws IOException
12451256 {
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 ));
12471258 indent (out , 2 , "#[inline]\n " );
12481259 indent (out , 2 , "fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {\n " );
12491260 indent (out , 3 , "&mut self.buf\n " );
12501261 indent (out , 2 , "}\n " );
12511262 indent (out , 1 , "}\n \n " );
12521263
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 ));
12541265 indent (out , 2 , "#[inline]\n " );
12551266 indent (out , 2 , "fn get_limit(&self) -> usize {\n " );
12561267 indent (out , 3 , "self.limit\n " );
@@ -1268,21 +1279,21 @@ static void appendImplDecoderTrait(
12681279 final Appendable out ,
12691280 final String typeName ) throws IOException
12701281 {
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 ));
12721283 indent (out , 2 , "#[inline]\n " );
12731284 indent (out , 2 , "fn acting_version(&self) -> %s {\n " , schemaVersionType );
12741285 indent (out , 3 , "self.acting_version\n " );
12751286 indent (out , 2 , "}\n " );
12761287 indent (out , 1 , "}\n \n " );
12771288
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 ));
12791290 indent (out , 2 , "#[inline]\n " );
12801291 indent (out , 2 , "fn get_buf(&self) -> &ReadBuf<'a> {\n " );
12811292 indent (out , 3 , "&self.buf\n " );
12821293 indent (out , 2 , "}\n " );
12831294 indent (out , 1 , "}\n \n " );
12841295
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 ));
12861297 indent (out , 2 , "#[inline]\n " );
12871298 indent (out , 2 , "fn get_limit(&self) -> usize {\n " );
12881299 indent (out , 3 , "self.limit\n " );
0 commit comments