Skip to main content

SigmfExtension

Trait SigmfExtension 

Source
pub trait SigmfExtension: Serialize + DeserializeOwned {
    const NAMESPACE: &'static str;
    const VERSION: &'static str;
    const SCOPE: ExtensionScope;
    const FIELDS: &'static [&'static str];

    // Provided methods
    fn to_extension_value(&self) -> Result<Value, SigmfError> { ... }
    fn from_extension_value(value: Value) -> Result<Self, SigmfError>
       where Self: Sized { ... }
    fn declaration(optional: bool) -> ExtensionDeclaration { ... }
}
Expand description

A typed view of one SigMF extension’s fields within a single scope.

The type is serialized with Serde to a JSON object whose keys are the namespaced wire names (e.g. "antenna:port"), so fields normally use #[serde(rename = "namespace:field")]. Every key it serializes must be listed in FIELDS.

With the derive feature, #[derive(sigmf::SigmfExtension)] together with #[sigmf(namespace = "...", version = "...", scope = "...")] implements this trait, filling in the associated constants and checking at compile time that every field’s Serde name uses the namespace prefix. See the module documentation for a manual implementation.

Required Associated Constants§

Source

const NAMESPACE: &'static str

The extension namespace, i.e. the prefix before : in field names.

Must be non-empty and must not be "core". The derive macro takes it from #[sigmf(namespace = "...")] and additionally requires ASCII alphanumerics, _, or -.

Source

const VERSION: &'static str

The extension version written to core:extensions.

Must be non-empty. The derive macro takes it from #[sigmf(version = "...")].

Source

const SCOPE: ExtensionScope

The object in which this extension’s fields appear.

The derive macro maps #[sigmf(scope = "...")] values "global", "capture", "annotation", and "collection" to the corresponding ExtensionScope variant.

Source

const FIELDS: &'static [&'static str]

The complete set of namespaced wire field names this type owns.

Only these keys are read by the typed getters and replaced or removed by the typed setters; other fields are left untouched. The derive macro fills this with each struct field’s Serde wire name.

Provided Methods§

Source

fn to_extension_value(&self) -> Result<Value, SigmfError>

Serializes self to a JSON value.

§Errors

Returns SigmfError::Serde if serialization fails.

Source

fn from_extension_value(value: Value) -> Result<Self, SigmfError>
where Self: Sized,

Deserializes an extension from a JSON value.

§Errors

Returns SigmfError::InvalidMetadata if value does not match the type, e.g. because a required field is missing.

Source

fn declaration(optional: bool) -> ExtensionDeclaration

Builds the core:extensions entry declaring this extension.

optional indicates whether readers may ignore the extension.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§