-
Notifications
You must be signed in to change notification settings - Fork 38
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
refactor: make Kind a lot smaller #82
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::type_aliases::Map; | ||
use std::hash::Hash; | ||
use std::{hash::Hash, ops::Index}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum SmallMap<K, V> { | ||
|
@@ -146,6 +146,13 @@ impl<K, V> SmallMap<K, V> { | |
} | ||
} | ||
|
||
impl<K: PartialEq + Eq + Hash, V> Index<&K> for SmallMap<K, V> { | ||
type Output = V; | ||
fn index(&self, key: &K) -> &V { | ||
&self.get(key).unwrap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading |
||
} | ||
} | ||
|
||
impl<K: Eq + Hash + Clone, V: Clone> SmallMap<K, V> { | ||
pub fn as_map(&self) -> Map<K, V> { | ||
match self { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,14 @@ impl<V: Version> Term<V> { | |
_ => panic!("Negative term cannot unwrap positive range"), | ||
} | ||
} | ||
|
||
/// Unwrap the range contains in the term. | ||
pub(crate) fn as_range(&self) -> &Range<V> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a big fan of this function either. |
||
match self { | ||
Self::Positive(range) => range, | ||
Self::Negative(range) => range, | ||
} | ||
} | ||
} | ||
|
||
/// Set operations with terms. | ||
|
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.
I think things like
NoVersion(P)
might imply that there is no version at all for package P while actually that's limited to a given range.