pub struct DataCloud<'a, K: PartialEq + Eq + Hash, V: PartialEq + Eq, S = FxBuildHasher> { /* private fields */ }Expand description
An abstract data structure can store values without moving them.
§Examples
use cloudr::DataCloud;
let data: DataCloud<'_, String, String> = DataCloud::new();
let x = "Hello master".to_string();
let y = String::from("hello, world!");
data.insert("x".to_string(), &x);
data.insert("y".to_string(), &y);
assert_eq!(&y, data.get(&"y".to_string()).unwrap());Implementations§
Source§impl<'a, K: PartialEq + Eq + Hash, V: PartialEq + Eq> DataCloud<'a, K, V>
impl<'a, K: PartialEq + Eq + Hash, V: PartialEq + Eq> DataCloud<'a, K, V>
Sourcepub fn new() -> DataCloud<'a, K, V>
pub fn new() -> DataCloud<'a, K, V>
Returns a new instance of a DataCloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();Sourcepub fn insert(&self, key: K, value: &'a V) -> Option<&'a V>
pub fn insert(&self, key: K, value: &'a V) -> Option<&'a V>
Inserts a new key into the cloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
let inserted_before: Option<&i32> = cloud.insert("y".to_string(), &y);
Sourcepub fn or_insert(&self, key: K, value: &'a V) -> bool
pub fn or_insert(&self, key: K, value: &'a V) -> bool
Inserts a new key into the cloud if the key doesn’t already exist, and returns whether the key was inserted or not.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.or_insert("y".to_string(), &y);Sourcepub fn get(&self, key_to_search_for: &K) -> Option<&'a V>
pub fn get(&self, key_to_search_for: &K) -> Option<&'a V>
Gets the reference stored in the cloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let y_ref: Option<&i32> = cloud.get(&"y".to_string());
assert_eq!(&y, y_ref.unwrap());Sourcepub fn get_mut(&self, key_to_search_for: &K) -> Option<&'a mut V>
pub fn get_mut(&self, key_to_search_for: &K) -> Option<&'a mut V>
Gets the reference stored in the cloud as a mutable reference.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let mut y = 3;
cloud.insert("y".to_string(), &mut y);
let y_ref: Option<&mut i32> = cloud.get_mut(&"y".to_string());Sourcepub fn remove(&self, key: &K) -> Option<&'a V>
pub fn remove(&self, key: &K) -> Option<&'a V>
Removes the reference stored in the cloud and returns it if it exists.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let mut y = 3;
cloud.insert("y".to_string(), &mut y);
let y_ref = cloud.remove(&"y".to_string()).unwrap();Sourcepub fn merge_in_place(&self, other: DataCloud<'a, K, V>)
pub fn merge_in_place(&self, other: DataCloud<'a, K, V>)
Merges in place the DataCloud with the other one by consuming the other DataCloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let cloud2: DataCloud<'_, String, i32> = DataCloud::new();
let x = 56;
cloud2.insert("x".to_string(), &x);
cloud.merge_in_place(cloud2);Sourcepub fn merge_with(self, other: &DataCloud<'a, K, V>)
pub fn merge_with(self, other: &DataCloud<'a, K, V>)
Merges in place the other DataCloud with this one by consuming this DataCloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let cloud2: DataCloud<'_, String, i32> = DataCloud::new();
let x = 56;
cloud2.insert("x".to_string(), &x);
cloud2.merge_with(&cloud);
println!("{:?}", cloud);Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns if the cloud contains a reference indexed by this key.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let mut x = 63;
cloud.insert("x".to_string(), &mut x);
assert!(cloud.contains_key(&"x".to_string()));Sourcepub fn contains_value(&self, key: &V) -> bool
pub fn contains_value(&self, key: &V) -> bool
Returns if the cloud contains the specified reference as a value.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let x = 63;
cloud.insert("x".to_string(), &x);
assert!(cloud.contains_value(&x));Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns if the cloud does not contain any key-value pairs.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
assert!(cloud.is_empty());Sourcepub fn into_pairs(self) -> IntoPairs<K, &'a V> ⓘ
pub fn into_pairs(self) -> IntoPairs<K, &'a V> ⓘ
Returns the cloud into an iterator of (K, &'a V) key-value pairs in arbitrary order.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let mut x = 63;
cloud.insert("x".to_string(), &mut x);
for (key, value) in cloud.into_pairs() {
println!("({key}: {value})");
}Sourcepub unsafe fn into_raw_pairs(self) -> IntoPairs<K, *mut V> ⓘ
pub unsafe fn into_raw_pairs(self) -> IntoPairs<K, *mut V> ⓘ
Returns the cloud into an iterator of (K, *mut V) key-value pairs in arbitrary order.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let mut x = 63;
cloud.insert("x".to_string(), &mut x);
for (key, value) in cloud.into_pairs() {
println!("({key}: {})", *value);
}Sourcepub fn clear(&self)
pub fn clear(&self)
Clears the DataCloud’s key-value pairs into a fresh, new one.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, usize, i128> = DataCloud::new();
let v = 54;
cloud.insert(3, &v);
cloud.clear();
assert_eq!(DataCloud::new(), cloud);Sourcepub unsafe fn insert_from_raw(
&self,
key: K,
value: *const V,
) -> Result<Option<&'a V>, NullPointerError>
pub unsafe fn insert_from_raw( &self, key: K, value: *const V, ) -> Result<Option<&'a V>, NullPointerError>
Inserts a new key into the cloud from a raw pointer
§Examples
use cloudr::DataCloud;
use cloudr::error::NullPointerError;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
let inserted_before: Result<Option<&i32>, NullPointerError> = unsafe {
cloud.insert_from_raw("y".to_string(), &y as *const i32)
};
Sourcepub unsafe fn get_as_raw(&self, key_to_search_for: &K) -> Option<*mut V>
pub unsafe fn get_as_raw(&self, key_to_search_for: &K) -> Option<*mut V>
Gets the reference stored in the cloud as a mutable raw pointer.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let pointer: Option<*mut i32> = unsafe {
cloud.get_as_raw(&"y".to_string())
};Sourcepub fn from_hashmap(hashmap: FxHashMap<K, &'a V>) -> DataCloud<'a, K, V>
pub fn from_hashmap(hashmap: FxHashMap<K, &'a V>) -> DataCloud<'a, K, V>
Builds a new DataCloud from a FxHashMap<K, &'a V>.
§Examples
use cloudr::DataCloud;
use fxhash::FxHashMap;
let mut map: FxHashMap<String, &i32> = FxHashMap::default();
let y = 3;
map.insert("y".to_string(), &y);
let cloud = DataCloud::from_hashmap(map);Sourcepub fn map<F>(&self, f: F) -> Map<K, V> ⓘ
pub fn map<F>(&self, f: F) -> Map<K, V> ⓘ
Calls a function for each key-value pair of the cloud and returns an iterator over the resulted pairs.
§Examples
use cloudr::DataCloud;
use cloudr::iter::Map;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let iterator: Map<String, i32> = cloud.map(|(k, v)| { return ( k.to_uppercase(), **v - 1 ) });Sourcepub fn iter(&'a self) -> Iter<'a, K, V> ⓘ
pub fn iter(&'a self) -> Iter<'a, K, V> ⓘ
Returns an iterator over the elements of the cloud as &'a references.
§Examples
use cloudr::DataCloud;
use cloudr::iter::Iter;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let mut iterator: Iter<'_, String, i32> = cloud.iter();
assert_eq!((&"y".to_string(), &&3), iterator.next().unwrap());Sourcepub fn iter_mut(&'a self) -> IterMut<'a, K, V> ⓘ
pub fn iter_mut(&'a self) -> IterMut<'a, K, V> ⓘ
Returns an iterator over the elements of the cloud as &'a mut references.
§Examples
use cloudr::DataCloud;
use cloudr::iter::IterMut;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let mut iterator: IterMut<'_, String, i32> = cloud.iter_mut();
assert_eq!((&"y".to_string(), &mut &3), iterator.next().unwrap());Sourcepub fn into_vec(self) -> Vec<(K, &'a V)>
pub fn into_vec(self) -> Vec<(K, &'a V)>
Consumes the DataCloud and returns a vector of tuples containing (K, &'a V).
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let mut vec: Vec<(String, &i32)> = cloud.into_vec();
assert_eq!(vec, vec![("y".to_string(), &y)]);Sourcepub fn into_vecdeque(self) -> VecDeque<(K, &'a V)>
pub fn into_vecdeque(self) -> VecDeque<(K, &'a V)>
Consumes the DataCloud and returns a VecDeque of tuples containing (K, &'a V).
§Examples
use cloudr::DataCloud;
use std::collections::VecDeque;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let mut vec: VecDeque<(String, &i32)> = cloud.into_vecdeque();Sourcepub fn insert_all(&self, pairs: Vec<(K, &'a V)>) -> Vec<Option<&'a V>>
pub fn insert_all(&self, pairs: Vec<(K, &'a V)>) -> Vec<Option<&'a V>>
Inserts multiple elements at a time in the DataCloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let x = 42;
let y = 24;
let pairs: Vec<(String, &i32)> = vec![("x".to_string(), &x), ("y".to_string(), &y)];
cloud.insert_all(pairs);Sourcepub fn get_all(&self, keys: Vec<&K>) -> Vec<Option<&'a V>>
pub fn get_all(&self, keys: Vec<&K>) -> Vec<Option<&'a V>>
Gets multiple elements at a time in the DataCloud.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let x = 42;
let y = 24;
let x_string = "x".to_string();
let y_string = "y".to_string();
cloud.insert("x".to_string(), &x);
cloud.insert("y".to_string(), &y);
let pairs = vec![&x_string, &y_string];
assert_eq!(cloud.get_all(pairs), vec![Some(&x), Some(&y)])Sourcepub fn get_mut_all(&self, keys: Vec<&K>) -> Vec<Option<&'a mut V>>
pub fn get_mut_all(&self, keys: Vec<&K>) -> Vec<Option<&'a mut V>>
Gets multiple elements at a time in the DataCloud as mutable references.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let mut x = 42;
let mut y = 24;
let x_string = "x".to_string();
let y_string = "y".to_string();
cloud.insert("x".to_string(), &x);
cloud.insert("y".to_string(), &y);
let pairs = vec![&x_string, &y_string];
let mut_pairs: Vec<Option<&mut i32>> = cloud.get_mut_all(pairs);Sourcepub fn as_ptr(&self) -> *const DataCloud<'a, K, V>
pub fn as_ptr(&self) -> *const DataCloud<'a, K, V>
Returns the DataCloud as a constant pointer to a DataCloud<'a, K, V>.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let pointer: *const DataCloud<'_, String, i32> = cloud.as_ptr();Sourcepub fn as_boxed_ref(&self) -> Box<&FxHashMap<K, &'a V>>
pub fn as_boxed_ref(&self) -> Box<&FxHashMap<K, &'a V>>
Returns the DataCloud’s inner HashMap as a boxed shared reference Box<&HashMap<K, &'a V, S>.
§Examples
use cloudr::DataCloud;
use fxhash::FxHashMap;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let boxed_ref: Box<&FxHashMap<String, &i32>> = cloud.as_boxed_ref();Sourcepub unsafe fn as_boxed_ptr(&self) -> Box<*const FxHashMap<K, &'a V>>
pub unsafe fn as_boxed_ptr(&self) -> Box<*const FxHashMap<K, &'a V>>
Returns the DataCloud’s inner HashMap as a boxed raw pointer Box<*const HashMap<K, &'a V, S>.
§Examples
use cloudr::DataCloud;
use fxhash::FxHashMap;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let boxed_ptr: Box<*const FxHashMap<String, &i32>> = unsafe {
cloud.as_boxed_ptr()
};Sourcepub unsafe fn as_boxed_mut(&self) -> Box<&mut FxHashMap<K, &'a V>>
pub unsafe fn as_boxed_mut(&self) -> Box<&mut FxHashMap<K, &'a V>>
Returns the DataCloud’s inner HashMap as a boxed mutable reference Box<&mut HashMap<K, &'a V, S>.
§Examples
use cloudr::DataCloud;
use fxhash::FxHashMap;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let boxed_ref: Box<&mut FxHashMap<String, &i32>> = unsafe {
cloud.as_boxed_mut()
};Sourcepub fn retain<F>(&self, predicate: F)
pub fn retain<F>(&self, predicate: F)
Retains only the elements specified by the predicate function.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<String, i32> = DataCloud::new();
cloud.insert("x".to_string(), &42);
cloud.insert("y".to_string(), &24);
cloud.retain(|key, value| {
*value > &30
});
assert!(cloud.contains_key(&"x".to_string()));
assert!(!cloud.contains_key(&"y".to_string()));Sourcepub fn from_vec<T: Into<Vec<(K, &'a V)>>>(vec: T) -> Self
pub fn from_vec<T: Into<Vec<(K, &'a V)>>>(vec: T) -> Self
Returns a new DataCloud from the given vector of keys and values Vec<(K, &'a V)>.
§Examples
use cloudr::DataCloud;
let mut vector = Vec::new();
vector.push((String::from("Banana"), &1));
let cloud: DataCloud<'_, String, i32> = DataCloud::from_vec(vector);Source§impl<'a, K: PartialEq + Eq + Hash + Clone, V: PartialEq + Eq + Clone> DataCloud<'a, K, V>
impl<'a, K: PartialEq + Eq + Hash + Clone, V: PartialEq + Eq + Clone> DataCloud<'a, K, V>
Sourcepub fn merge(&self, other: &DataCloud<'a, K, V>) -> DataCloud<'a, K, V>
pub fn merge(&self, other: &DataCloud<'a, K, V>) -> DataCloud<'a, K, V>
Merges the DataCloud with another and returns the resulting one. The other DataCloud will always have priority. So, if there are two conflicting keys, the other one will always have priority.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<String, i32> = DataCloud::new();
cloud.insert("x".to_string(), &42);
cloud.insert("y".to_string(), &24);
let cloud2: DataCloud<String, i32> = DataCloud::new();
cloud2.insert("z".to_string(), &64);
assert!(cloud.merge(&cloud2).contains_key(&"z".to_string()));Sourcepub fn merge_all(
&self,
others: Vec<&DataCloud<'a, K, V>>,
) -> DataCloud<'a, K, V>
pub fn merge_all( &self, others: Vec<&DataCloud<'a, K, V>>, ) -> DataCloud<'a, K, V>
Merges the DataCloud with other instances and returns the resulting one.
The last element of the vector others will always have priority. So, if
there are two conflicting keys, the last one will always have priority.
§Examples
use cloudr::DataCloud;
let cloud: DataCloud<String, i32> = DataCloud::new();
cloud.insert("x".to_string(), &42);
cloud.insert("y".to_string(), &24);
let cloud2: DataCloud<String, i32> = DataCloud::new();
cloud2.insert("z".to_string(), &64);
assert!(cloud.merge_all(vec![&cloud2]).contains_key(&"z".to_string()));Trait Implementations§
Source§impl<'a, K: PartialEq + Eq + Hash + Clone, V: PartialEq + Eq> CombineWith for DataCloud<'a, K, V>
impl<'a, K: PartialEq + Eq + Hash + Clone, V: PartialEq + Eq> CombineWith for DataCloud<'a, K, V>
Source§fn combine_with(&self, others: Vec<Self>) -> Selfwhere
Self: Sized,
fn combine_with(&self, others: Vec<Self>) -> Selfwhere
Self: Sized,
Enables the DataCloud to combine with other instances of the same type
§Examples
use cloudr::DataCloud;
use cloudr::CombineWith;
let cloud: DataCloud<'_, String, i32> = DataCloud::new();
let y = 3;
cloud.insert("y".to_string(), &y);
let cloud2: DataCloud<'_, String, i32> = DataCloud::new();
let x = 4;
cloud2.insert("x".to_string(), &x);
let final_cloud: DataCloud<'_, String, i32> = cloud.combine_with(vec![cloud2]);
let cloud3: DataCloud<'_, String, i32> = DataCloud::new();
cloud3.insert("y".to_string(), &y);
cloud3.insert("x".to_string(), &x);
assert_eq!(final_cloud, cloud3);Source§impl<'a, K: PartialEq + Eq + Hash + Clone + Debug, V: PartialEq + Eq + Debug> Debug for DataCloud<'a, K, V>
impl<'a, K: PartialEq + Eq + Hash + Clone + Debug, V: PartialEq + Eq + Debug> Debug for DataCloud<'a, K, V>
Source§impl<'a, K: PartialEq + Eq + Hash + Clone + Display, V: PartialEq + Eq + Display> Display for DataCloud<'a, K, V>
impl<'a, K: PartialEq + Eq + Hash + Clone + Display, V: PartialEq + Eq + Display> Display for DataCloud<'a, K, V>
Source§impl<'a, K: PartialEq + Eq + Hash, V: PartialEq + Eq> Extend<(K, &'a V)> for DataCloud<'a, K, V>
impl<'a, K: PartialEq + Eq + Hash, V: PartialEq + Eq> Extend<(K, &'a V)> for DataCloud<'a, K, V>
Source§fn extend<T: IntoIterator<Item = (K, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, &'a V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)