pub struct CollectionMetadata {
pub version: String,
pub description: Option<String>,
pub author: Option<String>,
pub collection_doi: Option<String>,
pub license: Option<String>,
pub extensions: Option<Vec<ExtensionDeclaration>>,
pub streams: Vec<RecordingRef>,
/* private fields */
}Expand description
The collection object of a .sigmf-collection document.
Fields not modeled here, such as extension fields, are preserved in
extra_fields. Typed extension access is available
through extension and related methods.
Fields§
§version: Stringcore:version: the SigMF version of the collection (required).
description: Option<String>core:description: a text description of the collection.
core:author: the author’s name and optionally email address.
collection_doi: Option<String>core:collection_doi: the registered DOI for the collection.
license: Option<String>core:license: a URL for the license under which the collection is
offered.
extensions: Option<Vec<ExtensionDeclaration>>core:extensions: the extensions used by the collection.
streams: Vec<RecordingRef>core:streams: references to the recordings in the collection
(required).
Both the object form and the legacy [name, hash] tuple form are
accepted when deserializing; references are serialized as objects.
Implementations§
Source§impl CollectionMetadata
impl CollectionMetadata
Sourcepub fn new(version: impl Into<String>, streams: Vec<RecordingRef>) -> Self
pub fn new(version: impl Into<String>, streams: Vec<RecordingRef>) -> Self
Creates a collection object with the given version and stream
references and no optional fields.
§Example
use sigmf::collection::CollectionMetadata;
use sigmf::recording::RecordingRef;
let hash = "ab".repeat(64);
let mut metadata = CollectionMetadata::new(
"1.2.6",
vec![RecordingRef::new("rx0", &hash), RecordingRef::new("rx1", &hash)],
);
metadata.author = Some("Jane Doe <jane@example.com>".into());
assert_eq!(metadata.streams.len(), 2);
assert!(metadata.extensions.is_none());Sourcepub fn extra_fields(&self) -> &Map<String, Value>
pub fn extra_fields(&self) -> &Map<String, Value>
Returns the preserved fields not modeled by this struct, such as extension fields.
Sourcepub fn insert_extra(
&mut self,
key: impl Into<String>,
value: Value,
) -> Result<Option<Value>, SigmfError>
pub fn insert_extra( &mut self, key: impl Into<String>, value: Value, ) -> Result<Option<Value>, SigmfError>
Inserts or replaces a preserved field, such as an extension field.
Returns the previous value for key, if any.
§Errors
Returns SigmfError::InvalidMetadata
if key names a field modeled by this struct (e.g. core:version or
core:streams).
Source§impl CollectionMetadata
impl CollectionMetadata
Sourcepub fn extension<T: SigmfExtension>(&self) -> Result<T, SigmfError>
pub fn extension<T: SigmfExtension>(&self) -> Result<T, SigmfError>
Reads extension T from this collection object’s fields.
Only the keys listed in SigmfExtension::FIELDS are considered;
absent keys are simply omitted before deserialization.
§Errors
Returns SigmfError::InvalidMetadata if T’s scope is not
ExtensionScope::Collection or the fields do not deserialize into T.
Sourcepub fn set_extension<T: SigmfExtension>(
&mut self,
extension: &T,
) -> Result<(), SigmfError>
pub fn set_extension<T: SigmfExtension>( &mut self, extension: &T, ) -> Result<(), SigmfError>
Writes extension T into this collection object.
All of T’s declared FIELDS are first
removed, then the serialized fields are inserted, so fields omitted by
serialization are cleared. core:extensions is not modified.
§Errors
Returns SigmfError::InvalidMetadata if T’s scope is not
ExtensionScope::Collection, extension does not serialize to a JSON
object, or it serializes a key not listed in FIELDS; returns
SigmfError::Serde if serialization fails. Nothing is changed on
error.
Sourcepub fn remove_extension<T: SigmfExtension>(&mut self) -> Result<(), SigmfError>
pub fn remove_extension<T: SigmfExtension>(&mut self) -> Result<(), SigmfError>
Removes all of extension T’s declared fields from this collection object.
§Errors
Returns SigmfError::InvalidMetadata if T’s scope is not
ExtensionScope::Collection.
Trait Implementations§
Source§impl Clone for CollectionMetadata
impl Clone for CollectionMetadata
Source§impl Debug for CollectionMetadata
impl Debug for CollectionMetadata
Source§impl<'de> Deserialize<'de> for CollectionMetadata
impl<'de> Deserialize<'de> for CollectionMetadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CollectionMetadata
impl RefUnwindSafe for CollectionMetadata
impl Send for CollectionMetadata
impl Sync for CollectionMetadata
impl Unpin for CollectionMetadata
impl UnsafeUnpin for CollectionMetadata
impl UnwindSafe for CollectionMetadata
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
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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 more