Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
41 changes: 41 additions & 0 deletions src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,30 @@ 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[..]
}
}

#[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 +3299,23 @@ 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");
}

#[test]
fn length_limited_read_write_string() {
// Exact limit, success
Expand Down
41 changes: 41 additions & 0 deletions xdr-generator-rust/generator/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,30 @@ 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[..]
}
}

#[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 +3215,23 @@ 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");
}

#[test]
fn length_limited_read_write_string() {
// Exact limit, success
Expand Down
Loading