From b22f76712c9ed29d22188f35ead80a489c679160 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 2 Oct 2026 11:54:48 +0000 Subject: [PATCH 1/3] add PartialEq for StringM with byte strings --- src/generated.rs | 35 ++++++++++++++++++++++++++ xdr-generator-rust/generator/header.rs | 35 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/generated.rs b/src/generated.rs index a65270d97..8dd04aca0 100644 --- a/src/generated.rs +++ b/src/generated.rs @@ -2292,6 +2292,30 @@ impl AsRef<[u8]> for StringM { } } +impl PartialEq<[u8]> for StringM { + fn eq(&self, other: &[u8]) -> bool { + self.0[..] == other[..] + } +} + +impl PartialEq<&[u8]> for StringM { + fn eq(&self, other: &&[u8]) -> bool { + self.0[..] == other[..] + } +} + +impl PartialEq<[u8; N]> for StringM { + fn eq(&self, other: &[u8; N]) -> bool { + self.0[..] == other[..] + } +} + +impl PartialEq<&[u8; N]> for StringM { + fn eq(&self, other: &&[u8; N]) -> bool { + self.0[..] == other[..] + } +} + #[cfg(feature = "alloc")] impl TryFrom<[u8; N]> for StringM { type Error = Error; @@ -3275,6 +3299,17 @@ mod test { ); } + #[test] + fn stringm_eq_byte_strings() { + let v = StringM::<3>::try_from("123").unwrap(); + assert_eq!(v, *b"123"); + assert_eq!(v, b"123"); + assert_eq!(v, b"123"[..]); + assert_eq!(v, &b"123"[..]); + assert_ne!(v, b"12"); + assert_ne!(v, &b"124"[..]); + } + #[test] fn length_limited_read_write_string() { // Exact limit, success diff --git a/xdr-generator-rust/generator/header.rs b/xdr-generator-rust/generator/header.rs index b67bc8913..1cc9f3abe 100644 --- a/xdr-generator-rust/generator/header.rs +++ b/xdr-generator-rust/generator/header.rs @@ -2208,6 +2208,30 @@ impl AsRef<[u8]> for StringM { } } +impl PartialEq<[u8]> for StringM { + fn eq(&self, other: &[u8]) -> bool { + self.0[..] == other[..] + } +} + +impl PartialEq<&[u8]> for StringM { + fn eq(&self, other: &&[u8]) -> bool { + self.0[..] == other[..] + } +} + +impl PartialEq<[u8; N]> for StringM { + fn eq(&self, other: &[u8; N]) -> bool { + self.0[..] == other[..] + } +} + +impl PartialEq<&[u8; N]> for StringM { + fn eq(&self, other: &&[u8; N]) -> bool { + self.0[..] == other[..] + } +} + #[cfg(feature = "alloc")] impl TryFrom<[u8; N]> for StringM { type Error = Error; @@ -3191,6 +3215,17 @@ mod test { ); } + #[test] + fn stringm_eq_byte_strings() { + let v = StringM::<3>::try_from("123").unwrap(); + assert_eq!(v, *b"123"); + assert_eq!(v, b"123"); + assert_eq!(v, b"123"[..]); + assert_eq!(v, &b"123"[..]); + assert_ne!(v, b"12"); + assert_ne!(v, &b"124"[..]); + } + #[test] fn length_limited_read_write_string() { // Exact limit, success From 2b06c6f2aa2f139d0356c45cf90508351e851bee Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 2 Oct 2026 12:03:56 +0000 Subject: [PATCH 2/3] add inequality cases to StringM byte string test --- src/generated.rs | 8 +++++++- xdr-generator-rust/generator/header.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/generated.rs b/src/generated.rs index 8dd04aca0..f8902c8d4 100644 --- a/src/generated.rs +++ b/src/generated.rs @@ -3306,8 +3306,14 @@ mod test { assert_eq!(v, b"123"); assert_eq!(v, b"123"[..]); assert_eq!(v, &b"123"[..]); - assert_ne!(v, b"12"); + assert_ne!(v, *b"124"); + assert_ne!(v, b"124"); + assert_ne!(v, b"124"[..]); assert_ne!(v, &b"124"[..]); + assert_ne!(v, b"12"); + assert_ne!(v, &b"1234"[..]); + assert_ne!(v, b""); + assert_ne!(StringM::<3>::default(), b"1"); } #[test] diff --git a/xdr-generator-rust/generator/header.rs b/xdr-generator-rust/generator/header.rs index 1cc9f3abe..290a6220d 100644 --- a/xdr-generator-rust/generator/header.rs +++ b/xdr-generator-rust/generator/header.rs @@ -3222,8 +3222,14 @@ mod test { assert_eq!(v, b"123"); assert_eq!(v, b"123"[..]); assert_eq!(v, &b"123"[..]); - assert_ne!(v, b"12"); + assert_ne!(v, *b"124"); + assert_ne!(v, b"124"); + assert_ne!(v, b"124"[..]); assert_ne!(v, &b"124"[..]); + assert_ne!(v, b"12"); + assert_ne!(v, &b"1234"[..]); + assert_ne!(v, b""); + assert_ne!(StringM::<3>::default(), b"1"); } #[test] From 38a2850d34b930bd664e1cb261891b5606f1fc2e Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 2 Oct 2026 12:52:17 +0000 Subject: [PATCH 3/3] add PartialEq for byte strings with StringM --- src/generated.rs | 36 ++++++++++++++++++++++++++ xdr-generator-rust/generator/header.rs | 36 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/generated.rs b/src/generated.rs index f8902c8d4..6f37944a7 100644 --- a/src/generated.rs +++ b/src/generated.rs @@ -2316,6 +2316,30 @@ impl PartialEq<&[u8; N]> for StringM { } } +impl PartialEq> for [u8] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + +impl PartialEq> for &[u8] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + +impl PartialEq> for [u8; N] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + +impl PartialEq> for &[u8; N] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + #[cfg(feature = "alloc")] impl TryFrom<[u8; N]> for StringM { type Error = Error; @@ -3314,6 +3338,18 @@ mod test { assert_ne!(v, &b"1234"[..]); assert_ne!(v, b""); assert_ne!(StringM::<3>::default(), b"1"); + assert_eq!(*b"123", v); + assert_eq!(b"123", v); + assert_eq!(b"123"[..], v); + assert_eq!(&b"123"[..], v); + assert_ne!(*b"124", v); + assert_ne!(b"124", v); + assert_ne!(b"124"[..], v); + assert_ne!(&b"124"[..], v); + assert_ne!(b"12", v); + assert_ne!(&b"1234"[..], v); + assert_ne!(b"", v); + assert_ne!(b"1", StringM::<3>::default()); } #[test] diff --git a/xdr-generator-rust/generator/header.rs b/xdr-generator-rust/generator/header.rs index 290a6220d..9d9bb028d 100644 --- a/xdr-generator-rust/generator/header.rs +++ b/xdr-generator-rust/generator/header.rs @@ -2232,6 +2232,30 @@ impl PartialEq<&[u8; N]> for StringM { } } +impl PartialEq> for [u8] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + +impl PartialEq> for &[u8] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + +impl PartialEq> for [u8; N] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + +impl PartialEq> for &[u8; N] { + fn eq(&self, other: &StringM) -> bool { + self[..] == other.0[..] + } +} + #[cfg(feature = "alloc")] impl TryFrom<[u8; N]> for StringM { type Error = Error; @@ -3230,6 +3254,18 @@ mod test { assert_ne!(v, &b"1234"[..]); assert_ne!(v, b""); assert_ne!(StringM::<3>::default(), b"1"); + assert_eq!(*b"123", v); + assert_eq!(b"123", v); + assert_eq!(b"123"[..], v); + assert_eq!(&b"123"[..], v); + assert_ne!(*b"124", v); + assert_ne!(b"124", v); + assert_ne!(b"124"[..], v); + assert_ne!(&b"124"[..], v); + assert_ne!(b"12", v); + assert_ne!(&b"1234"[..], v); + assert_ne!(b"", v); + assert_ne!(b"1", StringM::<3>::default()); } #[test]