Skip to content

Add PartialEq derive to Order#3467

Open
russellbanks wants to merge 1 commit into
google:mainfrom
russellbanks:order-partialeq
Open

Add PartialEq derive to Order#3467
russellbanks wants to merge 1 commit into
google:mainfrom
russellbanks:order-partialeq

Conversation

@russellbanks

Copy link
Copy Markdown

This pull request adds a PartialEq derive on Order in byteorder.rs.

While Order is marked hidden in documentation, the below use case illustrates why it would be helpful for it to implement PartialEq:

use std::borrow::Cow;

use zerocopy::{ByteOrder, U16, U32, transmute_ref};

enum Value<'a, O: ByteOrder> {
    Word(Cow<'a, [U16<O>]>),
    DWord(Cow<'a, [U32<O>]>),
}

impl<'a, O: ByteOrder> Value<'a, O> {
    pub fn to<P: ByteOrder>(&self) -> Value<'a, P> {
        if O::ORDER == P::ORDER {
            return match self {
                Self::Word(words) => Value::Word(Cow::Borrowed(transmute_ref!(&**words))),
                Self::DWord(dwords) => Value::DWord(Cow::Borrowed(transmute_ref!(&**dwords))),
            };
        }

        match self {
            Self::Word(words) => Value::Word(Cow::Owned(
                words.into_iter().map(|word| U16::new(word.get())).collect(),
            )),
            Self::DWord(dwords) => Value::DWord(Cow::Owned(
                dwords
                    .into_iter()
                    .map(|dword| U32::new(dword.get()))
                    .collect(),
            )),
        }
    }
}

@google-cla

google-cla Bot commented Jun 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (3b29d25) to head (7be2d32).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3467   +/-   ##
=======================================
  Coverage   91.85%   91.85%           
=======================================
  Files          20       20           
  Lines        6093     6093           
=======================================
  Hits         5597     5597           
  Misses        496      496           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants