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

fix: Ability needs PartialOrd, not Ord #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tennox
Copy link

@tennox tennox commented May 4, 2024

(as far as I understand)
Abilities can be compared, but aren't necessarily related. Nor do they have a 'total order'

Description

Given my simple example, where abilities have no hierarchy/relation:

#[derive(PartialEq, Eq, Clone, Debug)]
pub enum StorageAction {
    Read,
    Store,
    Pin,
}
impl Ability for StorageAction {}

Ord would require me to do this hack, pretending an ability is Less, which only works because Abilities are currently only compared via >=.

impl Ord for StorageAction {
    fn cmp(&self, other: &Self) -> Ordering {
        if self == other {
            Ordering::Equal
        } else {
            Ordering::Less
        }
    }
}

Correct, I think, would be PartialOrd:

impl PartialOrd for StorageAction {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        if self == other {
            Some(Ordering::Equal)
        } else {
            None
        }
    }
}

Of course, introducing hierarchy still works.

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Test plan (required)

I cargo buil[t] and cargo test[ed] 💁

(Afaik)
Abilities can be compared, but aren't necessarily related.
Nor do they have a 'total order'
@tennox tennox requested review from cdata and a team as code owners May 4, 2024 12:49
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.44%. Comparing base (83528cc) to head (de24d0c).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #129      +/-   ##
==========================================
- Coverage   62.12%   60.44%   -1.68%     
==========================================
  Files          24       24              
  Lines         895      890       -5     
  Branches      214      233      +19     
==========================================
- Hits          556      538      -18     
+ Misses        196      190       -6     
- Partials      143      162      +19     
Files Coverage Δ
ucan/src/capability/semantics.rs 47.52% <ø> (-0.52%) ⬇️

... and 14 files with indirect coverage changes

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