diff --git a/src/generated.rs b/src/generated.rs index a65270d97..6f37944a7 100644 --- a/src/generated.rs +++ b/src/generated.rs @@ -2292,6 +2292,54 @@ 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[..] + } +} + +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; @@ -3275,6 +3323,35 @@ 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"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"); + 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] 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..9d9bb028d 100644 --- a/xdr-generator-rust/generator/header.rs +++ b/xdr-generator-rust/generator/header.rs @@ -2208,6 +2208,54 @@ 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[..] + } +} + +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; @@ -3191,6 +3239,35 @@ 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"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"); + 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] fn length_limited_read_write_string() { // Exact limit, success