mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Store multiple abilities as a VecSet
This commit is contained in:
parent
603160dae3
commit
2011ec97c3
3 changed files with 27 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{borrow::Borrow, iter::FromIterator};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct VecSet<T> {
|
||||
elements: Vec<T>,
|
||||
}
|
||||
|
@ -26,6 +26,12 @@ impl<T: PartialEq> VecSet<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn singleton(element: T) -> Self {
|
||||
Self {
|
||||
elements: vec![element],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.elements.len()
|
||||
}
|
||||
|
@ -145,3 +151,11 @@ impl<T> From<Vec<T>> for VecSet<T> {
|
|||
Self { elements }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::ops::Deref for VecSet<T> {
|
||||
type Target = [T];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.elements
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue