pub struct SingleValuedMapping<K, V>{ /* private fields */ }Expand description
A mapping where all keys return the same value.
This is an optimization for cases like column qualification where many columns from the same table all map to the same table name. Instead of storing N copies of the value, we store it once.
§Example
use polyglot_sql::helper::SingleValuedMapping;
use std::collections::HashSet;
let columns = HashSet::from(["id".to_string(), "name".to_string(), "email".to_string()]);
let mapping = SingleValuedMapping::new(columns, "users".to_string());
assert_eq!(mapping.get(&"id".to_string()), Some(&"users".to_string()));
assert_eq!(mapping.get(&"name".to_string()), Some(&"users".to_string()));
assert_eq!(mapping.get(&"unknown".to_string()), None);
assert_eq!(mapping.len(), 3);Implementations§
Source§impl<K, V> SingleValuedMapping<K, V>
impl<K, V> SingleValuedMapping<K, V>
Sourcepub fn new(keys: HashSet<K>, value: V) -> Self
pub fn new(keys: HashSet<K>, value: V) -> Self
Create a new SingleValuedMapping from a set of keys and a single value.
Sourcepub fn from_iter<I: IntoIterator<Item = K>>(keys: I, value: V) -> Self
pub fn from_iter<I: IntoIterator<Item = K>>(keys: I, value: V) -> Self
Create from an iterator of keys and a single value.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check if a key exists in the mapping.
Trait Implementations§
Source§impl<K, V: Clone> Clone for SingleValuedMapping<K, V>
impl<K, V: Clone> Clone for SingleValuedMapping<K, V>
Source§fn clone(&self) -> SingleValuedMapping<K, V>
fn clone(&self) -> SingleValuedMapping<K, V>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<K, V> Freeze for SingleValuedMapping<K, V>where
V: Freeze,
impl<K, V> RefUnwindSafe for SingleValuedMapping<K, V>where
V: RefUnwindSafe,
K: RefUnwindSafe,
impl<K, V> Send for SingleValuedMapping<K, V>
impl<K, V> Sync for SingleValuedMapping<K, V>
impl<K, V> Unpin for SingleValuedMapping<K, V>
impl<K, V> UnwindSafe for SingleValuedMapping<K, V>where
V: UnwindSafe,
K: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more