Implement native RLV state and permissions (#79)
Some checks failed
Native code generation / deterministic (push) Failing after 2m1s
Imaging and meshing gate / native (push) Successful in 5m22s
JPEG 2000 feature / linux (push) Successful in 2m45s
Native Rust workspace compile / compile (push) Failing after 6m12s
Skia feature / linux (push) Successful in 30m44s
Some checks failed
Native code generation / deterministic (push) Failing after 2m1s
Imaging and meshing gate / native (push) Successful in 5m22s
JPEG 2000 feature / linux (push) Successful in 2m45s
Native Rust workspace compile / compile (push) Failing after 6m12s
Skia feature / linux (push) Successful in 30m44s
This commit is contained in:
@@ -1151,7 +1151,100 @@ impl<T> Future for AsyncEnumerableNext<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ImmutableDictionary<TKey, TValue>(pub PhantomData<fn(TKey, TValue)>);
|
||||
/// Read-only, cheaply clonable hash-map snapshot corresponding to
|
||||
/// `System.Collections.Immutable.ImmutableDictionary<TKey, TValue>`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ImmutableDictionary<TKey, TValue>(Arc<std::collections::HashMap<TKey, TValue>>);
|
||||
|
||||
impl<TKey, TValue> PartialEq for ImmutableDictionary<TKey, TValue>
|
||||
where
|
||||
TKey: Eq + std::hash::Hash,
|
||||
TValue: PartialEq,
|
||||
{
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<TKey, TValue> Eq for ImmutableDictionary<TKey, TValue>
|
||||
where
|
||||
TKey: Eq + std::hash::Hash,
|
||||
TValue: Eq,
|
||||
{
|
||||
}
|
||||
|
||||
impl<TKey, TValue> ImmutableDictionary<TKey, TValue> {
|
||||
/// Creates an immutable snapshot from an owned map.
|
||||
#[must_use]
|
||||
pub fn from_map(values: std::collections::HashMap<TKey, TValue>) -> Self {
|
||||
Self(Arc::new(values))
|
||||
}
|
||||
|
||||
/// Returns the number of entries in the snapshot.
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
/// Returns whether the snapshot contains no entries.
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
/// Iterates over keys and values in the snapshot.
|
||||
#[must_use]
|
||||
pub fn iter(&self) -> std::collections::hash_map::Iter<'_, TKey, TValue> {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
/// Iterates over values in the snapshot.
|
||||
#[must_use]
|
||||
pub fn values(&self) -> std::collections::hash_map::Values<'_, TKey, TValue> {
|
||||
self.0.values()
|
||||
}
|
||||
|
||||
/// Looks up a value by borrowed key.
|
||||
#[must_use]
|
||||
pub fn get<Q>(&self, key: &Q) -> Option<&TValue>
|
||||
where
|
||||
TKey: std::borrow::Borrow<Q> + Eq + std::hash::Hash,
|
||||
Q: Eq + std::hash::Hash + ?Sized,
|
||||
{
|
||||
self.0.get(key)
|
||||
}
|
||||
}
|
||||
|
||||
impl<TKey, TValue> Default for ImmutableDictionary<TKey, TValue> {
|
||||
fn default() -> Self {
|
||||
Self(Arc::new(std::collections::HashMap::new()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<TKey, TValue> From<std::collections::HashMap<TKey, TValue>>
|
||||
for ImmutableDictionary<TKey, TValue>
|
||||
{
|
||||
fn from(values: std::collections::HashMap<TKey, TValue>) -> Self {
|
||||
Self::from_map(values)
|
||||
}
|
||||
}
|
||||
|
||||
impl<TKey, TValue> std::ops::Deref for ImmutableDictionary<TKey, TValue> {
|
||||
type Target = std::collections::HashMap<TKey, TValue>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, TKey, TValue> IntoIterator for &'a ImmutableDictionary<TKey, TValue> {
|
||||
type Item = (&'a TKey, &'a TValue);
|
||||
type IntoIter = std::collections::hash_map::Iter<'a, TKey, TValue>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// Read-only, cheaply clonable snapshot corresponding to
|
||||
/// `System.Collections.Immutable.ImmutableList<T>`.
|
||||
|
||||
Reference in New Issue
Block a user