-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
universal-query: New QueriedPoint
struct with extendable Score
enum
#4251
Conversation
Closing in favor of #4291 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It got closed right when I was done 🥲
match (&self.score, &other.score) { | ||
(Some(a), Some(b)) => a.cmp(b), | ||
(None, Some(_)) => Ordering::Less, | ||
(Some(_), None) => Ordering::Greater, | ||
(None, None) => self.id.cmp(&other.id), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option
implements Ord
where None
is always less, so you could do this with a bit less branching:
match (&self.score, &other.score) { | |
(Some(a), Some(b)) => a.cmp(b), | |
(None, Some(_)) => Ordering::Less, | |
(Some(_), None) => Ordering::Greater, | |
(None, None) => self.id.cmp(&other.id), | |
} | |
if self.score.is_some() || other.score.is_some() { | |
self.score.cmp(&other.score) | |
} else { | |
self.id.cmp(&other.id) | |
} |
Or maybe you want this instead:
self.score.cmp(&other.score).then_with(|| self.id.cmp(&other.id))
QueriedPoint
struct, which is equivalent to aScoredPoint
, but has aScore
enum, which can be used to be the output of scroll-like requests, like when specifyingorder_by
.query
to be ofQueriedPoint
type.