Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,54 @@ impl<const MAX: u32> AsRef<[u8]> for StringM<MAX> {
}
}

impl<const MAX: u32> PartialEq<[u8]> for StringM<MAX> {
fn eq(&self, other: &[u8]) -> bool {
self.0[..] == other[..]
}
}

impl<const MAX: u32> PartialEq<&[u8]> for StringM<MAX> {
fn eq(&self, other: &&[u8]) -> bool {
self.0[..] == other[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<[u8; N]> for StringM<MAX> {
fn eq(&self, other: &[u8; N]) -> bool {
self.0[..] == other[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<&[u8; N]> for StringM<MAX> {
fn eq(&self, other: &&[u8; N]) -> bool {
self.0[..] == other[..]
}
}

impl<const MAX: u32> PartialEq<StringM<MAX>> for [u8] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

impl<const MAX: u32> PartialEq<StringM<MAX>> for &[u8] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<StringM<MAX>> for [u8; N] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<StringM<MAX>> for &[u8; N] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

#[cfg(feature = "alloc")]
impl<const N: usize, const MAX: u32> TryFrom<[u8; N]> for StringM<MAX> {
type Error = Error;
Expand Down Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions xdr-generator-rust/generator/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,54 @@ impl<const MAX: u32> AsRef<[u8]> for StringM<MAX> {
}
}

impl<const MAX: u32> PartialEq<[u8]> for StringM<MAX> {
fn eq(&self, other: &[u8]) -> bool {
self.0[..] == other[..]
}
}
Comment thread
leighmcculloch marked this conversation as resolved.
Resolved
Comment thread
Copilot marked this conversation as resolved.
Resolved

impl<const MAX: u32> PartialEq<&[u8]> for StringM<MAX> {
fn eq(&self, other: &&[u8]) -> bool {
self.0[..] == other[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<[u8; N]> for StringM<MAX> {
fn eq(&self, other: &[u8; N]) -> bool {
self.0[..] == other[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<&[u8; N]> for StringM<MAX> {
fn eq(&self, other: &&[u8; N]) -> bool {
self.0[..] == other[..]
}
}

impl<const MAX: u32> PartialEq<StringM<MAX>> for [u8] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

impl<const MAX: u32> PartialEq<StringM<MAX>> for &[u8] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<StringM<MAX>> for [u8; N] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

impl<const N: usize, const MAX: u32> PartialEq<StringM<MAX>> for &[u8; N] {
fn eq(&self, other: &StringM<MAX>) -> bool {
self[..] == other.0[..]
}
}

#[cfg(feature = "alloc")]
impl<const N: usize, const MAX: u32> TryFrom<[u8; N]> for StringM<MAX> {
type Error = Error;
Expand Down Expand Up @@ -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
Expand Down
Loading