pub struct Sample { /* private fields */ }Expand description
One training example: an insertion-ordered map from file extension to value.
Fields whose names start with __ are metadata and are skipped by decoding,
encoding, and key extraction.
use webdataset_core::{Sample, Value};
let mut sample = Sample::with_key("image0001");
sample.insert("cls", Value::Int(7));
sample.insert("txt", Value::Text("a caption".into()));
assert_eq!(sample.key(), Some("image0001"));
assert_eq!(sample.get("cls").and_then(Value::as_i64), Some(7));
assert_eq!(sample.field_names(), vec!["cls", "txt"]);Implementations§
Source§impl Sample
impl Sample
Sourcepub fn local_path(&self) -> Option<&str>
pub fn local_path(&self) -> Option<&str>
The on-disk path of the shard, when it was read or cached locally.
Sourcepub fn get_first(&self, names: &[&str]) -> Option<&Value>
pub fn get_first(&self, names: &[&str]) -> Option<&Value>
Look up the first field that exists among several alternatives.
Alternatives are given either as a slice or, following the Python API,
as a single ;-separated string (see Sample::get_first_spec).
Sourcepub fn get_first_spec(&self, spec: &str) -> Option<&Value>
pub fn get_first_spec(&self, spec: &str) -> Option<&Value>
Look up the first field named by a ;-separated alternation such as
"png;jpg;jpeg".
Sourcepub fn require_first_spec(&self, spec: &str) -> Result<&Value>
pub fn require_first_spec(&self, spec: &str) -> Result<&Value>
Like Sample::get_first_spec but reports which alternatives were tried.
Sourcepub fn insert(
&mut self,
name: impl Into<String>,
value: impl Into<Value>,
) -> Option<Value>
pub fn insert( &mut self, name: impl Into<String>, value: impl Into<Value>, ) -> Option<Value>
Insert a field, returning the value it replaced.
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Whether a field is present.
Sourcepub fn field_names(&self) -> Vec<&str>
pub fn field_names(&self) -> Vec<&str>
The names of the data (non-__) fields.
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Sample
impl<'a> IntoIterator for &'a Sample
Source§impl IntoIterator for Sample
impl IntoIterator for Sample
impl StructuralPartialEq for Sample
Auto Trait Implementations§
impl !RefUnwindSafe for Sample
impl !UnwindSafe for Sample
impl Freeze for Sample
impl Send for Sample
impl Sync for Sample
impl Unpin for Sample
impl UnsafeUnpin for Sample
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CustomValue for T
impl<T> CustomValue for T
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> ⓘ
Converts
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> ⓘ
Converts
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
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().