pub struct InfoDict { /* private fields */ }
Expand description
An info dictionary type.
Implementations§
source§impl InfoDict
impl InfoDict
This type provides convenient access to key/value data returned by
the “INFO” command. It acts like a regular mapping but also has
a convenience method get
which can return data in the appropriate
type.
For instance this can be used to query the server for the role it’s in (master, slave) etc:
let info : redis::InfoDict = redis::cmd("INFO").query(&mut con)?;
let role : Option<String> = info.get("role");
sourcepub fn new(kvpairs: &str) -> InfoDict
pub fn new(kvpairs: &str) -> InfoDict
Creates a new info dictionary from a string in the response of
the INFO command. Each line is a key, value pair with the
key and value separated by a colon (:
). Lines starting with a
hash (#
) are ignored.
sourcepub fn get<T: FromRedisValue>(&self, key: &str) -> Option<T>
pub fn get<T: FromRedisValue>(&self, key: &str) -> Option<T>
Fetches a value by key and converts it into the given type.
Typical types are String
, bool
and integer types.
sourcepub fn contains_key(&self, key: &&str) -> bool
pub fn contains_key(&self, key: &&str) -> bool
Checks if a key is contained in the info dicf.
Methods from Deref<Target = HashMap<String, Value>>§
1.0.0 · sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the HashMap<K, V>
might be able to hold
more, but is guaranteed to be able to hold at least this many.
§Examples
use std::collections::HashMap;
let map: HashMap<i32, i32> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);
1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K
.
§Examples
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for key in map.keys() {
println!("{key}");
}
§Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V
.
§Examples
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for val in map.values() {
println!("{val}");
}
§Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V)
.
§Examples
use std::collections::HashMap;
let map = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
for (key, val) in map.iter() {
println!("key: {key} val: {val}");
}
§Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
1.0.0 · sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
§Examples
use std::collections::HashMap;
let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
1.0.0 · sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
§Examples
use std::collections::HashMap;
let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
1.9.0 · sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
§Examples
use std::collections::HashMap;
use std::hash::RandomState;
let hasher = RandomState::new();
let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();
1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
§Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
§Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
assert_eq!(map.get_key_value(&2), None);
1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
§Examples
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
sourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
hash_raw_entry
)Creates a raw immutable entry builder for the HashMap.
Raw entries provide the lowest level of control for searching and manipulating a map. They must be manually initialized with a hash and then manually searched.
This is useful for
- Hash memoization
- Using a search key that doesn’t work with the Borrow trait
- Using custom comparison logic without newtype wrappers
Unless you are in such a situation, higher-level and more foolproof APIs like
get
should be preferred.
Immutable raw entries have very limited use; you might instead want raw_entry_mut
.
Trait Implementations§
source§impl FromRedisValue for InfoDict
impl FromRedisValue for InfoDict
source§fn from_redis_value(v: &Value) -> RedisResult<InfoDict>
fn from_redis_value(v: &Value) -> RedisResult<InfoDict>
Value
this attempts to convert it into the given
destination type. If that fails because it’s not compatible an
appropriate error is generated.source§fn from_owned_redis_value(v: Value) -> RedisResult<InfoDict>
fn from_owned_redis_value(v: Value) -> RedisResult<InfoDict>
Value
this attempts to convert it into the given
destination type. If that fails because it’s not compatible an
appropriate error is generated.source§fn from_redis_values(items: &[Value]) -> RedisResult<Vec<Self>>
fn from_redis_values(items: &[Value]) -> RedisResult<Vec<Self>>
from_redis_value
but constructs a vector of objects
from another vector of values. This primarily exists internally
to customize the behavior for vectors of tuples.source§fn from_owned_redis_values(items: Vec<Value>) -> RedisResult<Vec<Self>>
fn from_owned_redis_values(items: Vec<Value>) -> RedisResult<Vec<Self>>
from_redis_values
, but takes a Vec<Value>
instead
of a &[Value]
.source§fn from_owned_byte_vec(_vec: Vec<u8>) -> RedisResult<Vec<Self>>
fn from_owned_byte_vec(_vec: Vec<u8>) -> RedisResult<Vec<Self>>
Auto Trait Implementations§
impl Freeze for InfoDict
impl RefUnwindSafe for InfoDict
impl Send for InfoDict
impl Sync for InfoDict
impl Unpin for InfoDict
impl UnwindSafe for InfoDict
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)