@@ -52,6 +52,7 @@ public class RustGenerator implements CodeGenerator
5252{
5353 static final String WRITE_BUF_TYPE = "WriteBuf" ;
5454 static final String READ_BUF_TYPE = "ReadBuf" ;
55+ static final String ANONYMOUS_LIFETIME = "'_" ;
5556 static final String BUF_LIFETIME = "'a" ;
5657
5758 enum CodecType
@@ -189,9 +190,19 @@ String schemaVersionType()
189190 return rustTypeName (ir .headerStructure ().schemaVersionType ());
190191 }
191192
192- static String withLifetime (final String typeName )
193+ static String withAnonymousLifetime (final String typeName )
193194 {
194- return format ("%s<%s>" , typeName , BUF_LIFETIME );
195+ return withLifetime (typeName , ANONYMOUS_LIFETIME );
196+ }
197+
198+ static String withBufLifetime (final String typeName )
199+ {
200+ return withLifetime (typeName , BUF_LIFETIME );
201+ }
202+
203+ private static String withLifetime (final String typeName , final String lifetime )
204+ {
205+ return format ("%s<%s>" , typeName , lifetime );
195206 }
196207
197208 static void appendImplWithLifetimeHeader (
@@ -1281,14 +1292,14 @@ static void appendImplEncoderTrait(
12811292 final Appendable out ,
12821293 final String typeName ) throws IOException
12831294 {
1284- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Writer" ), withLifetime (typeName ));
1295+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Writer" ), withBufLifetime (typeName ));
12851296 indent (out , 2 , "#[inline]\n " );
12861297 indent (out , 2 , "fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {\n " );
12871298 indent (out , 3 , "&mut self.buf\n " );
12881299 indent (out , 2 , "}\n " );
12891300 indent (out , 1 , "}\n \n " );
12901301
1291- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Encoder" ), withLifetime (typeName ));
1302+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Encoder" ), withBufLifetime (typeName ));
12921303 indent (out , 2 , "#[inline]\n " );
12931304 indent (out , 2 , "fn get_limit(&self) -> usize {\n " );
12941305 indent (out , 3 , "self.limit\n " );
@@ -1306,21 +1317,21 @@ static void appendImplDecoderTrait(
13061317 final Appendable out ,
13071318 final String typeName ) throws IOException
13081319 {
1309- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , "ActingVersion" , withLifetime (typeName ));
1320+ indent (out , 1 , "impl %s for %s {\n " , "ActingVersion" , withAnonymousLifetime (typeName ));
13101321 indent (out , 2 , "#[inline]\n " );
13111322 indent (out , 2 , "fn acting_version(&self) -> %s {\n " , schemaVersionType );
13121323 indent (out , 3 , "self.acting_version\n " );
13131324 indent (out , 2 , "}\n " );
13141325 indent (out , 1 , "}\n \n " );
13151326
1316- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Reader" ), withLifetime (typeName ));
1327+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Reader" ), withBufLifetime (typeName ));
13171328 indent (out , 2 , "#[inline]\n " );
13181329 indent (out , 2 , "fn get_buf(&self) -> &ReadBuf<'a> {\n " );
13191330 indent (out , 3 , "&self.buf\n " );
13201331 indent (out , 2 , "}\n " );
13211332 indent (out , 1 , "}\n \n " );
13221333
1323- indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withLifetime ("Decoder" ), withLifetime (typeName ));
1334+ indent (out , 1 , "impl<%s> %s for %s {\n " , BUF_LIFETIME , withBufLifetime ("Decoder" ), withBufLifetime (typeName ));
13241335 indent (out , 2 , "#[inline]\n " );
13251336 indent (out , 2 , "fn get_limit(&self) -> usize {\n " );
13261337 indent (out , 3 , "self.limit\n " );
0 commit comments