diff --git a/samples/rust_generated/my_game/sample/vec_3_generated.rs b/samples/rust_generated/my_game/sample/vec_3_generated.rs index bc5e52a6751..f939c19ee03 100644 --- a/samples/rust_generated/my_game/sample/vec_3_generated.rs +++ b/samples/rust_generated/my_game/sample/vec_3_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Vec3, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Vec3(pub [u8; 12]); impl Default for Vec3 { fn default() -> Self { @@ -27,6 +27,18 @@ impl core::fmt::Debug for Vec3 { .finish() } } +impl core::cmp::Ord for Vec3 { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.x().total_cmp(&other.x()) + .then(self.y().total_cmp(&other.y())) + .then(self.z().total_cmp(&other.z())) + } +} +impl core::cmp::PartialOrd for Vec3 { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Vec3 {} impl<'a> flatbuffers::Follow<'a> for Vec3 { diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index b8811c6f3ff..9cc11db22e1 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -2625,7 +2625,7 @@ class RustGenerator : public BaseGenerator { // hold for PartialOrd/Ord. code_ += "// struct {{STRUCT_TY}}, aligned to {{ALIGN}}"; code_ += "#[repr(transparent)]"; - code_ += "#[derive(Clone, Copy, PartialEq)]"; + code_ += "#[derive(Clone, Copy, PartialEq, Eq)]"; code_ += "{{ACCESS_TYPE}} struct {{STRUCT_TY}}(pub [u8; {{STRUCT_SIZE}}]);"; code_ += "impl Default for {{STRUCT_TY}} { "; code_ += " fn default() -> Self { "; @@ -2646,6 +2646,30 @@ class RustGenerator : public BaseGenerator { code_ += " .finish()"; code_ += " }"; code_ += "}"; + + // Ord for structs. + code_ += "impl core::cmp::Ord for {{STRUCT_TY}} {"; + code_ += " fn cmp(&self, other: &Self) -> core::cmp::Ordering {"; + bool first = true; + ForAllStructFields(struct_def, [&](const FieldDef &field) { + // Floating point types don't impl Ord, use `total_cmp` instead. + const auto cmp_fn = + IsFloat(field.value.type.base_type) ? "total_cmp" : "cmp"; + const auto cmp_expr = "self." + namer_.Field(field) + "()." + cmp_fn + + "(&other." + namer_.Field(field) + "())"; + // If we are not the first comparison, we use `then` to chain. + code_ += first ? " " + cmp_expr : " .then(" + cmp_expr + ")"; + first = false; + }); + code_ += " }"; + code_ += "}"; + + // PartialOrd for structs. + code_ += "impl core::cmp::PartialOrd for {{STRUCT_TY}} {"; + code_ += " fn partial_cmp(&self, other: &Self) -> Option {"; + code_ += " Some(self.cmp(other))"; + code_ += " }"; + code_ += "}"; code_ += ""; // Generate impls for SafeSliceAccess (because all structs are endian-safe), diff --git a/tests/arrays_test/my_game/example/array_struct_generated.rs b/tests/arrays_test/my_game/example/array_struct_generated.rs index 65c7ca6cfcf..cf17ca1fd53 100644 --- a/tests/arrays_test/my_game/example/array_struct_generated.rs +++ b/tests/arrays_test/my_game/example/array_struct_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct ArrayStruct, aligned to 8 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct ArrayStruct(pub [u8; 160]); impl Default for ArrayStruct { fn default() -> Self { @@ -30,6 +30,21 @@ impl core::fmt::Debug for ArrayStruct { .finish() } } +impl core::cmp::Ord for ArrayStruct { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().total_cmp(&other.a()) + .then(self.b().cmp(&other.b())) + .then(self.c().cmp(&other.c())) + .then(self.d().cmp(&other.d())) + .then(self.e().cmp(&other.e())) + .then(self.f().cmp(&other.f())) + } +} +impl core::cmp::PartialOrd for ArrayStruct { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for ArrayStruct {} impl<'a> flatbuffers::Follow<'a> for ArrayStruct { diff --git a/tests/arrays_test/my_game/example/nested_struct_generated.rs b/tests/arrays_test/my_game/example/nested_struct_generated.rs index 0015f228260..534a1a205b3 100644 --- a/tests/arrays_test/my_game/example/nested_struct_generated.rs +++ b/tests/arrays_test/my_game/example/nested_struct_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct NestedStruct, aligned to 8 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct NestedStruct(pub [u8; 32]); impl Default for NestedStruct { fn default() -> Self { @@ -28,6 +28,19 @@ impl core::fmt::Debug for NestedStruct { .finish() } } +impl core::cmp::Ord for NestedStruct { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + .then(self.b().cmp(&other.b())) + .then(self.c().cmp(&other.c())) + .then(self.d().cmp(&other.d())) + } +} +impl core::cmp::PartialOrd for NestedStruct { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for NestedStruct {} impl<'a> flatbuffers::Follow<'a> for NestedStruct { diff --git a/tests/include_test1/my_game/other_name_space/unused_generated.rs b/tests/include_test1/my_game/other_name_space/unused_generated.rs index 11af62f073b..8b111164bd2 100644 --- a/tests/include_test1/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test1/my_game/other_name_space/unused_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Unused(pub [u8; 4]); impl Default for Unused { fn default() -> Self { @@ -25,6 +25,16 @@ impl core::fmt::Debug for Unused { .finish() } } +impl core::cmp::Ord for Unused { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + } +} +impl core::cmp::PartialOrd for Unused { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Unused {} impl<'a> flatbuffers::Follow<'a> for Unused { diff --git a/tests/include_test2/my_game/other_name_space/unused_generated.rs b/tests/include_test2/my_game/other_name_space/unused_generated.rs index 11af62f073b..8b111164bd2 100644 --- a/tests/include_test2/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test2/my_game/other_name_space/unused_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Unused(pub [u8; 4]); impl Default for Unused { fn default() -> Self { @@ -25,6 +25,16 @@ impl core::fmt::Debug for Unused { .finish() } } +impl core::cmp::Ord for Unused { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + } +} +impl core::cmp::PartialOrd for Unused { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Unused {} impl<'a> flatbuffers::Follow<'a> for Unused { diff --git a/tests/monster_test/my_game/example/ability_generated.rs b/tests/monster_test/my_game/example/ability_generated.rs index 0cef974d6ef..e1079183e66 100644 --- a/tests/monster_test/my_game/example/ability_generated.rs +++ b/tests/monster_test/my_game/example/ability_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Ability, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Ability(pub [u8; 8]); impl Default for Ability { fn default() -> Self { @@ -26,6 +26,17 @@ impl core::fmt::Debug for Ability { .finish() } } +impl core::cmp::Ord for Ability { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.id().cmp(&other.id()) + .then(self.distance().cmp(&other.distance())) + } +} +impl core::cmp::PartialOrd for Ability { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Ability {} impl<'a> flatbuffers::Follow<'a> for Ability { diff --git a/tests/monster_test/my_game/example/struct_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_generated.rs index 675a846cd70..56af25ae712 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructOfStructs, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct StructOfStructs(pub [u8; 20]); impl Default for StructOfStructs { fn default() -> Self { @@ -27,6 +27,18 @@ impl core::fmt::Debug for StructOfStructs { .finish() } } +impl core::cmp::Ord for StructOfStructs { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + .then(self.b().cmp(&other.b())) + .then(self.c().cmp(&other.c())) + } +} +impl core::cmp::PartialOrd for StructOfStructs { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {} impl<'a> flatbuffers::Follow<'a> for StructOfStructs { diff --git a/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs index 3eaa7055638..8350feedacf 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructOfStructsOfStructs, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct StructOfStructsOfStructs(pub [u8; 20]); impl Default for StructOfStructsOfStructs { fn default() -> Self { @@ -25,6 +25,16 @@ impl core::fmt::Debug for StructOfStructsOfStructs { .finish() } } +impl core::cmp::Ord for StructOfStructsOfStructs { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + } +} +impl core::cmp::PartialOrd for StructOfStructsOfStructs { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {} impl<'a> flatbuffers::Follow<'a> for StructOfStructsOfStructs { diff --git a/tests/monster_test/my_game/example/test_generated.rs b/tests/monster_test/my_game/example/test_generated.rs index 65ef25031d3..ae380c1b9c8 100644 --- a/tests/monster_test/my_game/example/test_generated.rs +++ b/tests/monster_test/my_game/example/test_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Test, aligned to 2 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Test(pub [u8; 4]); impl Default for Test { fn default() -> Self { @@ -26,6 +26,17 @@ impl core::fmt::Debug for Test { .finish() } } +impl core::cmp::Ord for Test { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + .then(self.b().cmp(&other.b())) + } +} +impl core::cmp::PartialOrd for Test { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Test {} impl<'a> flatbuffers::Follow<'a> for Test { diff --git a/tests/monster_test/my_game/example/vec_3_generated.rs b/tests/monster_test/my_game/example/vec_3_generated.rs index 8aebab50a2c..d6f281468f1 100644 --- a/tests/monster_test/my_game/example/vec_3_generated.rs +++ b/tests/monster_test/my_game/example/vec_3_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Vec3, aligned to 8 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Vec3(pub [u8; 32]); impl Default for Vec3 { fn default() -> Self { @@ -30,6 +30,21 @@ impl core::fmt::Debug for Vec3 { .finish() } } +impl core::cmp::Ord for Vec3 { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.x().total_cmp(&other.x()) + .then(self.y().total_cmp(&other.y())) + .then(self.z().total_cmp(&other.z())) + .then(self.test1().total_cmp(&other.test1())) + .then(self.test2().cmp(&other.test2())) + .then(self.test3().cmp(&other.test3())) + } +} +impl core::cmp::PartialOrd for Vec3 { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Vec3 {} impl<'a> flatbuffers::Follow<'a> for Vec3 { diff --git a/tests/monster_test/my_game/other_name_space/unused_generated.rs b/tests/monster_test/my_game/other_name_space/unused_generated.rs index 11af62f073b..8b111164bd2 100644 --- a/tests/monster_test/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test/my_game/other_name_space/unused_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Unused(pub [u8; 4]); impl Default for Unused { fn default() -> Self { @@ -25,6 +25,16 @@ impl core::fmt::Debug for Unused { .finish() } } +impl core::cmp::Ord for Unused { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + } +} +impl core::cmp::PartialOrd for Unused { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Unused {} impl<'a> flatbuffers::Follow<'a> for Unused { diff --git a/tests/monster_test_serialize/my_game/example/ability_generated.rs b/tests/monster_test_serialize/my_game/example/ability_generated.rs index 88f380206c1..73fd091a84d 100644 --- a/tests/monster_test_serialize/my_game/example/ability_generated.rs +++ b/tests/monster_test_serialize/my_game/example/ability_generated.rs @@ -13,7 +13,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Ability, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Ability(pub [u8; 8]); impl Default for Ability { fn default() -> Self { @@ -28,6 +28,17 @@ impl core::fmt::Debug for Ability { .finish() } } +impl core::cmp::Ord for Ability { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.id().cmp(&other.id()) + .then(self.distance().cmp(&other.distance())) + } +} +impl core::cmp::PartialOrd for Ability { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Ability {} impl<'a> flatbuffers::Follow<'a> for Ability { diff --git a/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs b/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs index e524059f807..ffe04dd0120 100644 --- a/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs @@ -13,7 +13,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructOfStructs, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct StructOfStructs(pub [u8; 20]); impl Default for StructOfStructs { fn default() -> Self { @@ -29,6 +29,18 @@ impl core::fmt::Debug for StructOfStructs { .finish() } } +impl core::cmp::Ord for StructOfStructs { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + .then(self.b().cmp(&other.b())) + .then(self.c().cmp(&other.c())) + } +} +impl core::cmp::PartialOrd for StructOfStructs { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {} impl<'a> flatbuffers::Follow<'a> for StructOfStructs { diff --git a/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs b/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs index b7fd8cd7cf9..10a5cbf021b 100644 --- a/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs +++ b/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs @@ -13,7 +13,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructOfStructsOfStructs, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct StructOfStructsOfStructs(pub [u8; 20]); impl Default for StructOfStructsOfStructs { fn default() -> Self { @@ -27,6 +27,16 @@ impl core::fmt::Debug for StructOfStructsOfStructs { .finish() } } +impl core::cmp::Ord for StructOfStructsOfStructs { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + } +} +impl core::cmp::PartialOrd for StructOfStructsOfStructs { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {} impl<'a> flatbuffers::Follow<'a> for StructOfStructsOfStructs { diff --git a/tests/monster_test_serialize/my_game/example/test_generated.rs b/tests/monster_test_serialize/my_game/example/test_generated.rs index 0a0a48c7dbe..6b6bc0a6a9a 100644 --- a/tests/monster_test_serialize/my_game/example/test_generated.rs +++ b/tests/monster_test_serialize/my_game/example/test_generated.rs @@ -13,7 +13,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Test, aligned to 2 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Test(pub [u8; 4]); impl Default for Test { fn default() -> Self { @@ -28,6 +28,17 @@ impl core::fmt::Debug for Test { .finish() } } +impl core::cmp::Ord for Test { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + .then(self.b().cmp(&other.b())) + } +} +impl core::cmp::PartialOrd for Test { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Test {} impl<'a> flatbuffers::Follow<'a> for Test { diff --git a/tests/monster_test_serialize/my_game/example/vec_3_generated.rs b/tests/monster_test_serialize/my_game/example/vec_3_generated.rs index e4ff8f2a2a7..55d3180d5d5 100644 --- a/tests/monster_test_serialize/my_game/example/vec_3_generated.rs +++ b/tests/monster_test_serialize/my_game/example/vec_3_generated.rs @@ -13,7 +13,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Vec3, aligned to 8 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Vec3(pub [u8; 32]); impl Default for Vec3 { fn default() -> Self { @@ -32,6 +32,21 @@ impl core::fmt::Debug for Vec3 { .finish() } } +impl core::cmp::Ord for Vec3 { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.x().total_cmp(&other.x()) + .then(self.y().total_cmp(&other.y())) + .then(self.z().total_cmp(&other.z())) + .then(self.test1().total_cmp(&other.test1())) + .then(self.test2().cmp(&other.test2())) + .then(self.test3().cmp(&other.test3())) + } +} +impl core::cmp::PartialOrd for Vec3 { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Vec3 {} impl<'a> flatbuffers::Follow<'a> for Vec3 { diff --git a/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs b/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs index c89fab4ef78..2940a9d9604 100644 --- a/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs @@ -13,7 +13,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct Unused(pub [u8; 4]); impl Default for Unused { fn default() -> Self { @@ -27,6 +27,16 @@ impl core::fmt::Debug for Unused { .finish() } } +impl core::cmp::Ord for Unused { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + } +} +impl core::cmp::PartialOrd for Unused { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Unused {} impl<'a> flatbuffers::Follow<'a> for Unused { diff --git a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs index db22105b8e7..1f1fe7bdbde 100644 --- a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructInNestedNS, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct StructInNestedNS(pub [u8; 8]); impl Default for StructInNestedNS { fn default() -> Self { @@ -26,6 +26,17 @@ impl core::fmt::Debug for StructInNestedNS { .finish() } } +impl core::cmp::Ord for StructInNestedNS { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.a().cmp(&other.a()) + .then(self.b().cmp(&other.b())) + } +} +impl core::cmp::PartialOrd for StructInNestedNS { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {} impl<'a> flatbuffers::Follow<'a> for StructInNestedNS { diff --git a/tests/private_annotation_test/object_generated.rs b/tests/private_annotation_test/object_generated.rs index 382b0e42e92..722fba04020 100644 --- a/tests/private_annotation_test/object_generated.rs +++ b/tests/private_annotation_test/object_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Object, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub(crate) struct Object(pub [u8; 4]); impl Default for Object { fn default() -> Self { @@ -25,6 +25,16 @@ impl core::fmt::Debug for Object { .finish() } } +impl core::cmp::Ord for Object { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.value().cmp(&other.value()) + } +} +impl core::cmp::PartialOrd for Object { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for Object {} impl<'a> flatbuffers::Follow<'a> for Object { diff --git a/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs b/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs index 3c21e0803ba..7f988dcca8b 100644 --- a/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs @@ -11,7 +11,7 @@ use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct PossiblyReservedWords, aligned to 4 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct PossiblyReservedWords(pub [u8; 16]); impl Default for PossiblyReservedWords { fn default() -> Self { @@ -28,6 +28,19 @@ impl core::fmt::Debug for PossiblyReservedWords { .finish() } } +impl core::cmp::Ord for PossiblyReservedWords { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.follow_().total_cmp(&other.follow_()) + .then(self.push_().total_cmp(&other.push_())) + .then(self.size().total_cmp(&other.size())) + .then(self.alignment().total_cmp(&other.alignment())) + } +} +impl core::cmp::PartialOrd for PossiblyReservedWords { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} impl flatbuffers::SimpleToVerifyInSlice for PossiblyReservedWords {} impl<'a> flatbuffers::Follow<'a> for PossiblyReservedWords {