pub struct Collection {
pub collection: CollectionMetadata,
/* private fields */
}Expand description
A complete .sigmf-collection document.
Top-level fields other than collection are preserved in
extra_fields.
Fields§
§collection: CollectionMetadataThe collection object.
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn new(collection: CollectionMetadata) -> Self
pub fn new(collection: CollectionMetadata) -> Self
Creates a collection document with no extra top-level fields.
Sourcepub fn extra_fields(&self) -> &Map<String, Value>
pub fn extra_fields(&self) -> &Map<String, Value>
Returns the preserved top-level fields other than collection.
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, SigmfError>
pub fn from_slice(bytes: &[u8]) -> Result<Self, SigmfError>
Parses a collection document from JSON bytes.
Parsing is stricter than plain deserialization: duplicate object keys
are rejected, core:version and core:streams are required, each
stream must be a {"name", "hash"} object or a two-string legacy
tuple, and optional core: fields may not be null.
§Errors
Returns SigmfError::ResourceLimit
if bytes exceeds the 1,000,000-byte metadata limit,
SigmfError::InvalidJson if the input
is not valid JSON or contains duplicate keys, and
SigmfError::InvalidMetadata if
it is not a well-formed collection.
Sourcepub fn to_vec(&self) -> Result<Vec<u8>, SigmfError>
pub fn to_vec(&self) -> Result<Vec<u8>, SigmfError>
Serializes the collection to compact JSON.
All stream references are written in object form.
§Errors
Returns an error if serialization fails.
Sourcepub fn to_vec_preserving_stream_forms(&self) -> Result<Vec<u8>, SigmfError>
pub fn to_vec_preserving_stream_forms(&self) -> Result<Vec<u8>, SigmfError>
Serializes the collection to compact JSON, writing stream references
that were read as legacy [name, hash] tuples back as tuples.
Any extra fields on such references are dropped in tuple form.
§Errors
Returns an error if serialization fails.
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 top-level field.
Returns the previous value for key, if any.
§Errors
Returns SigmfError::InvalidMetadata
if key is "collection".
Source§impl Collection
impl Collection
Sourcepub fn validate(&self, policy: ValidationPolicy) -> ValidationReport
pub fn validate(&self, policy: ValidationPolicy) -> ValidationReport
Validates this collection against SigMF rules using policy.
Checks the collection version, that each stream’s recording name is a
safe relative path and is unique, that each metadata digest is 128
hexadecimal characters, unknown core: fields, and extension
declarations. Recording references are not resolved; see
Archive::validate_collection_references.
The returned report’s policy is None.
Sourcepub fn validate_with_registry(
&self,
policy: ValidationPolicy,
registry: &ExtensionRegistry,
) -> ValidationReport
pub fn validate_with_registry( &self, policy: ValidationPolicy, registry: &ExtensionRegistry, ) -> ValidationReport
Validates this collection, using registry to verify declared extensions.
Like validate, but extensions registered in
registry are treated as verified and their fields in the collection
object are checked for scope and field names.
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§impl Debug for Collection
impl Debug for Collection
Source§impl<'de> Deserialize<'de> for Collection
impl<'de> Deserialize<'de> for Collection
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 Collection
impl RefUnwindSafe for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl UnsafeUnpin for Collection
impl UnwindSafe for Collection
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