pub struct Xs { /* private fields */ }Expand description
Collection of named tensors with associated images and texts.
Implementations§
Source§impl Xs
impl Xs
Sourcepub fn into_map(self) -> HashMap<String, X>
pub fn into_map(self) -> HashMap<String, X>
Consumes self and returns the map field.
This method moves the owned value out of the struct without cloning.
§Returns
Returns the owned value of type HashMap < String, X >.
§Example
let obj = Xs::default().with_map(value);
let value = obj.into_map();
// obj is now consumed and cannot be usedGenerated by aksr - Builder pattern macro
Sourcepub fn take_map(&mut self) -> HashMap<String, X>
pub fn take_map(&mut self) -> HashMap<String, X>
Takes the map field and replaces it with Default::default().
This method moves the value out and replaces it with the default value, allowing you to continue using the struct.
§Returns
Returns the owned value of type HashMap < String, X >.
§Note
Requires the field type HashMap < String, X > to implement Default. Prefer this when you want to keep using the instance.
§Example
let mut obj = Xs::default().with_map(value);
let value = obj.take_map();
// obj.map is now set to Default::default()Generated by aksr - Builder pattern macro
Sourcepub fn with_names(self, x: &[&str]) -> Self
pub fn with_names(self, x: &[&str]) -> Self
Sets the names field from a slice of string slices.
§Arguments
x- A slice of string slices that will be automatically converted toVec<String>
§Returns
Returns Self for method chaining.
§Note
If the slice is empty, the field remains unchanged.
§Example
let obj = Xs::default().with_names(&["str1", "str2"]);Generated by aksr - Builder pattern macro
Sourcepub fn with_names_owned(self, x: &[String]) -> Self
pub fn with_names_owned(self, x: &[String]) -> Self
Sets the names field from a slice of owned strings.
§Arguments
x- A slice ofStringto be cloned into the vector
§Returns
Returns Self for method chaining.
§Note
This method is useful when you already have a Vec<String> and want to avoid converting to &[&str].
If the slice is empty, the field remains unchanged.
§Example
let strings = vec![String::from("a"), String::from("b")];
let obj = Xs::default().with_names_owned(&strings);Generated by aksr - Builder pattern macro
Sourcepub fn into_names(self) -> Vec<String>
pub fn into_names(self) -> Vec<String>
Consumes self and returns the names field.
This method moves the owned value out of the struct without cloning.
§Returns
Returns the owned value of type Vec < String >.
§Example
let obj = Xs::default().with_names(value);
let value = obj.into_names();
// obj is now consumed and cannot be usedGenerated by aksr - Builder pattern macro
Sourcepub fn take_names(&mut self) -> Vec<String>
pub fn take_names(&mut self) -> Vec<String>
Takes the names field and replaces it with Default::default().
This method moves the value out and replaces it with the default value, allowing you to continue using the struct.
§Returns
Returns the owned value of type Vec < String >.
§Note
Requires the field type Vec < String > to implement Default. Prefer this when you want to keep using the instance.
§Example
let mut obj = Xs::default().with_names(value);
let value = obj.take_names();
// obj.names is now set to Default::default()Generated by aksr - Builder pattern macro
Methods from Deref<Target = HashMap<String, X>>§
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<&str, i32> = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
let mut values: Vec<_> = map.keys().copied().collect();
values.sort();
assert_eq!(values, vec!["a", "b", "c"]);§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<&str, i32> = HashMap::from([
("a", 1),
("b", 2),
("c", 3),
]);
let mut values: Vec<_> = map.values().copied().collect();
values.sort();
assert_eq!(values, vec![1, 2, 3]);§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),
]);
let mut count = 0;
for (_key, _val) in map.iter() {
count += 1;
}
assert_eq!(count, 3);§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. This is potentially useful:
- for key types where non-identical keys can be considered equal;
- for getting the
&Kstored key value from a borrowed&Qlookup key; or - for getting a reference to a key with the same lifetime as the collection.
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;
use std::hash::{Hash, Hasher};
#[derive(Clone, Copy, Debug)]
struct S {
id: u32,
name: &'static str, // ignored by equality and hashing operations
}
impl PartialEq for S {
fn eq(&self, other: &S) -> bool {
self.id == other.id
}
}
impl Eq for S {}
impl Hash for S {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
let j_a = S { id: 1, name: "Jessica" };
let j_b = S { id: 1, name: "Jess" };
let p = S { id: 2, name: "Paul" };
assert_eq!(j_a, j_b);
let mut map = HashMap::new();
map.insert(j_a, "Paris");
assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
assert_eq!(map.get_key_value(&p), 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);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Xs
impl RefUnwindSafe for Xs
impl Send for Xs
impl Sync for Xs
impl Unpin for Xs
impl UnsafeUnpin for Xs
impl UnwindSafe for Xs
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.