diff --git a/goldens/rust/basic_generated.rs b/goldens/rust/basic_generated.rs index 2ed0ad8822c..821de0aa832 100644 --- a/goldens/rust/basic_generated.rs +++ b/goldens/rust/basic_generated.rs @@ -244,7 +244,7 @@ impl core::fmt::Debug for Universe<'_> { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_universe_unchecked`. -pub fn root_as_universe(buf: &[u8]) -> Result { +pub fn root_as_universe(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::root::(buf) } #[inline] @@ -254,7 +254,7 @@ pub fn root_as_universe(buf: &[u8]) -> Result Result { +pub fn size_prefixed_root_as_universe(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -287,14 +287,14 @@ pub fn size_prefixed_root_as_universe_with_opts<'b, 'o>( /// Assumes, without verification, that a buffer of bytes contains a Universe and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Universe`. -pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe { +pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> { unsafe { flatbuffers::root_unchecked::(buf) } } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed Universe and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Universe`. -pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe { +pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> { unsafe { flatbuffers::size_prefixed_root_unchecked::(buf) } } #[inline] diff --git a/rust/flexbuffers/src/builder/map.rs b/rust/flexbuffers/src/builder/map.rs index 73194c7bf96..a47b10a5b3e 100644 --- a/rust/flexbuffers/src/builder/map.rs +++ b/rust/flexbuffers/src/builder/map.rs @@ -43,7 +43,7 @@ impl<'a> MapBuilder<'a> { /// /// This will panic (in debug mode) if `key` contains internal nulls. #[inline] - pub fn start_vector(&mut self, key: &str) -> VectorBuilder { + pub fn start_vector(&mut self, key: &str) -> VectorBuilder<'_> { // Push the key that refers to this nested vector. self.builder.push_key(key); // Nested vector. @@ -58,7 +58,7 @@ impl<'a> MapBuilder<'a> { /// /// This will panic (in debug mode) if `key` contains internal nulls. #[inline] - pub fn start_map(&mut self, key: &str) -> MapBuilder { + pub fn start_map(&mut self, key: &str) -> MapBuilder<'_> { // Push the key that refers to this nested vector. self.builder.push_key(key); // Nested map. diff --git a/rust/flexbuffers/src/builder/vector.rs b/rust/flexbuffers/src/builder/vector.rs index 375d49e2aa7..8ef227f89be 100644 --- a/rust/flexbuffers/src/builder/vector.rs +++ b/rust/flexbuffers/src/builder/vector.rs @@ -36,7 +36,7 @@ impl<'a> VectorBuilder<'a> { } /// Starts a nested vector that will be pushed onto this vector when it is dropped. #[inline] - pub fn start_vector(&mut self) -> VectorBuilder { + pub fn start_vector(&mut self) -> VectorBuilder<'_> { let start = Some(self.builder.values.len()); VectorBuilder { builder: self.builder, @@ -45,7 +45,7 @@ impl<'a> VectorBuilder<'a> { } /// Starts a nested map that will be pushed onto this vector when it is dropped. #[inline] - pub fn start_map(&mut self) -> MapBuilder { + pub fn start_map(&mut self) -> MapBuilder<'_> { let start = Some(self.builder.values.len()); MapBuilder { builder: self.builder, diff --git a/samples/rust_generated/my_game/sample/monster_generated.rs b/samples/rust_generated/my_game/sample/monster_generated.rs index 0bbd11cc7e6..9f475c61872 100644 --- a/samples/rust_generated/my_game/sample/monster_generated.rs +++ b/samples/rust_generated/my_game/sample/monster_generated.rs @@ -407,7 +407,7 @@ impl MonsterT { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. -pub fn root_as_monster(buf: &[u8]) -> Result { +pub fn root_as_monster(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::root::(buf) } #[inline] @@ -417,7 +417,7 @@ pub fn root_as_monster(buf: &[u8]) -> Result Result { +pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -450,14 +450,14 @@ pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>( /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Monster`. -pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster { +pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { flatbuffers::root_unchecked::(buf) } } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`. -pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster { +pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { flatbuffers::size_prefixed_root_unchecked::(buf) } } #[inline] diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 6087a6a4a08..ad7e1bfdc11 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -2418,7 +2418,7 @@ class RustGenerator : public BaseGenerator { code_ += "/// `root_as_{{STRUCT_FN}}_unchecked`."; code_ += "pub fn root_as_{{STRUCT_FN}}(buf: &[u8]) " - "-> Result<{{STRUCT_TY}}, flatbuffers::InvalidFlatbuffer> {"; + "-> Result<{{STRUCT_TY}}<'_>, flatbuffers::InvalidFlatbuffer> {"; code_ += " flatbuffers::root::<{{STRUCT_TY}}>(buf)"; code_ += "}"; code_ += "#[inline]"; @@ -2430,7 +2430,7 @@ class RustGenerator : public BaseGenerator { code_ += "/// `size_prefixed_root_as_{{STRUCT_FN}}_unchecked`."; code_ += "pub fn size_prefixed_root_as_{{STRUCT_FN}}" - "(buf: &[u8]) -> Result<{{STRUCT_TY}}, " + "(buf: &[u8]) -> Result<{{STRUCT_TY}}<'_>, " "flatbuffers::InvalidFlatbuffer> {"; code_ += " flatbuffers::size_prefixed_root::<{{STRUCT_TY}}>(buf)"; code_ += "}"; @@ -2480,7 +2480,7 @@ class RustGenerator : public BaseGenerator { " `{{STRUCT_TY}}`."; code_ += "pub unsafe fn root_as_{{STRUCT_FN}}_unchecked" - "(buf: &[u8]) -> {{STRUCT_TY}} {"; + "(buf: &[u8]) -> {{STRUCT_TY}}<'_> {"; code_ += " unsafe { flatbuffers::root_unchecked::<{{STRUCT_TY}}>(buf) }"; code_ += "}"; code_ += "#[inline]"; @@ -2493,7 +2493,7 @@ class RustGenerator : public BaseGenerator { " size prefixed `{{STRUCT_TY}}`."; code_ += "pub unsafe fn size_prefixed_root_as_{{STRUCT_FN}}" - "_unchecked(buf: &[u8]) -> {{STRUCT_TY}} {"; + "_unchecked(buf: &[u8]) -> {{STRUCT_TY}}<'_> {"; code_ += " unsafe { flatbuffers::size_prefixed_root_unchecked::<{{STRUCT_TY}}>" "(buf) }"; diff --git a/tests/arrays_test/my_game/example/array_table_generated.rs b/tests/arrays_test/my_game/example/array_table_generated.rs index 6ee550cd6d0..0fe2e4214dc 100644 --- a/tests/arrays_test/my_game/example/array_table_generated.rs +++ b/tests/arrays_test/my_game/example/array_table_generated.rs @@ -149,7 +149,7 @@ impl ArrayTableT { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_array_table_unchecked`. -pub fn root_as_array_table(buf: &[u8]) -> Result { +pub fn root_as_array_table(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::root::(buf) } #[inline] @@ -159,7 +159,7 @@ pub fn root_as_array_table(buf: &[u8]) -> Result Result { +pub fn size_prefixed_root_as_array_table(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -192,14 +192,14 @@ pub fn size_prefixed_root_as_array_table_with_opts<'b, 'o>( /// Assumes, without verification, that a buffer of bytes contains a ArrayTable and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `ArrayTable`. -pub unsafe fn root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable { +pub unsafe fn root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable<'_> { unsafe { flatbuffers::root_unchecked::(buf) } } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed ArrayTable and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `ArrayTable`. -pub unsafe fn size_prefixed_root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable { +pub unsafe fn size_prefixed_root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable<'_> { unsafe { flatbuffers::size_prefixed_root_unchecked::(buf) } } pub const ARRAY_TABLE_IDENTIFIER: &str = "ARRT"; diff --git a/tests/monster_test/my_game/example/monster_generated.rs b/tests/monster_test/my_game/example/monster_generated.rs index ca35268b9f7..46bddea8495 100644 --- a/tests/monster_test/my_game/example/monster_generated.rs +++ b/tests/monster_test/my_game/example/monster_generated.rs @@ -1935,7 +1935,7 @@ impl MonsterT { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. -pub fn root_as_monster(buf: &[u8]) -> Result { +pub fn root_as_monster(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::root::(buf) } #[inline] @@ -1945,7 +1945,7 @@ pub fn root_as_monster(buf: &[u8]) -> Result Result { +pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -1978,14 +1978,14 @@ pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>( /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Monster`. -pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster { +pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { flatbuffers::root_unchecked::(buf) } } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`. -pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster { +pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { flatbuffers::size_prefixed_root_unchecked::(buf) } } pub const MONSTER_IDENTIFIER: &str = "MONS"; diff --git a/tests/monster_test_serialize/my_game/example/monster_generated.rs b/tests/monster_test_serialize/my_game/example/monster_generated.rs index 23b4529c061..995446d2edd 100644 --- a/tests/monster_test_serialize/my_game/example/monster_generated.rs +++ b/tests/monster_test_serialize/my_game/example/monster_generated.rs @@ -2162,7 +2162,7 @@ impl MonsterT { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. -pub fn root_as_monster(buf: &[u8]) -> Result { +pub fn root_as_monster(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::root::(buf) } #[inline] @@ -2172,7 +2172,7 @@ pub fn root_as_monster(buf: &[u8]) -> Result Result { +pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -2205,14 +2205,14 @@ pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>( /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Monster`. -pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster { +pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { flatbuffers::root_unchecked::(buf) } } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`. -pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster { +pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { flatbuffers::size_prefixed_root_unchecked::(buf) } } pub const MONSTER_IDENTIFIER: &str = "MONS"; diff --git a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs index 5349891c3de..06d741f5a7d 100644 --- a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs +++ b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs @@ -951,7 +951,7 @@ impl ScalarStuffT { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_scalar_stuff_unchecked`. -pub fn root_as_scalar_stuff(buf: &[u8]) -> Result { +pub fn root_as_scalar_stuff(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::root::(buf) } #[inline] @@ -961,7 +961,7 @@ pub fn root_as_scalar_stuff(buf: &[u8]) -> Result Result { +pub fn size_prefixed_root_as_scalar_stuff(buf: &[u8]) -> Result, flatbuffers::InvalidFlatbuffer> { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -994,14 +994,14 @@ pub fn size_prefixed_root_as_scalar_stuff_with_opts<'b, 'o>( /// Assumes, without verification, that a buffer of bytes contains a ScalarStuff and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `ScalarStuff`. -pub unsafe fn root_as_scalar_stuff_unchecked(buf: &[u8]) -> ScalarStuff { +pub unsafe fn root_as_scalar_stuff_unchecked(buf: &[u8]) -> ScalarStuff<'_> { unsafe { flatbuffers::root_unchecked::(buf) } } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed ScalarStuff and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `ScalarStuff`. -pub unsafe fn size_prefixed_root_as_scalar_stuff_unchecked(buf: &[u8]) -> ScalarStuff { +pub unsafe fn size_prefixed_root_as_scalar_stuff_unchecked(buf: &[u8]) -> ScalarStuff<'_> { unsafe { flatbuffers::size_prefixed_root_unchecked::(buf) } } pub const SCALAR_STUFF_IDENTIFIER: &str = "NULL";