Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add back missing derives #27

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

stevefan1999-personal
Copy link
Contributor

No description provided.

@chipsenkbeil
Copy link
Owner

@stevefan1999-personal is the implementation of PartialOrd and Ord what you would expect? Namely that variants are compared for order first, and then only if they are the same are the fields compared. Would look something like this, I believe.

impl PartialOrd for TypedPathBuf {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        match (self, other) {
            (TypedPathBuf::Unix(lhs), TypedPathBuf::Unix(rhs)) => lhs.partial_cmp(rhs),
            (TypedPathBuf::Windows(lhs), TypedPathBuf::Windows(rhs)) => lhs.partial_cmp(rhs),
            (TypedPathBuf::Unix(_), TypedPathBuf::Windows(_)) => Some(std::cmp::Ordering::Less),
            (TypedPathBuf::Windows(_), TypedPathBuf::Unix(_)) => Some(std::cmp::Ordering::Greater),
        }
    }
}

impl Ord for TypedPathBuf {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        match (self, other) {
            (TypedPathBuf::Unix(lhs), TypedPathBuf::Unix(rhs)) => lhs.cmp(rhs),
            (TypedPathBuf::Windows(lhs), TypedPathBuf::Windows(rhs)) => lhs.cmp(rhs),
            (TypedPathBuf::Unix(_), TypedPathBuf::Windows(_)) => std::cmp::Ordering::Less,
            (TypedPathBuf::Windows(_), TypedPathBuf::Unix(_)) => std::cmp::Ordering::Greater),
        }
    }
}

@stevefan1999-personal
Copy link
Contributor Author

Huh, interesting, I never through about the orderings of Unix path and Windows path...but if you don't have PartialOrd then you can't use TypedPathBuf as a key for BTreeMap

@chipsenkbeil
Copy link
Owner

We're in pre 1.0 release, so I'm fine bringing this in. Can always change the behavior later if needed. Thanks for the contribution!

@chipsenkbeil chipsenkbeil merged commit 000d7b9 into chipsenkbeil:main Jul 15, 2024
17 checks passed
@stevefan1999-personal
Copy link
Contributor Author

We're in pre 1.0 release, so I'm fine bringing this in. Can always change the behavior later if needed. Thanks for the contribution!

Thanks! Now I can use this with BTreeMap in no_std context

@chipsenkbeil
Copy link
Owner

@stevefan1999-personal you'll find this included in the 0.9.1 release 😄

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