pub struct ExtensionRegistry { /* private fields */ }Expand description
The set of extensions, by namespace and version, an application supports.
Pass a registry to
Metadata::validate_with_registry
or
Collection::validate_with_registry
so declared extensions are treated as verified and their fields are
checked against each extension’s SCOPE and
FIELDS.
§Example
use serde::{Deserialize, Serialize};
use sigmf::extensions::{ExtensionRegistry, ExtensionScope, SigmfExtension};
#[derive(Serialize, Deserialize)]
struct Lab {
#[serde(rename = "lab:gain_db")]
gain_db: f64,
}
impl SigmfExtension for Lab {
const NAMESPACE: &'static str = "lab";
const VERSION: &'static str = "1.0.0";
const SCOPE: ExtensionScope = ExtensionScope::Global;
const FIELDS: &'static [&'static str] = &["lab:gain_db"];
}
let mut registry = ExtensionRegistry::new();
registry.register::<Lab>()?;
assert!(registry.supports("lab", "1.0.0"));
assert!(!registry.supports("lab", "2.0.0"));
assert!(registry.supports_field("lab", "1.0.0", ExtensionScope::Global, "lab:gain_db"));
assert!(!registry.supports_scope("lab", "1.0.0", ExtensionScope::Capture));
// Registering the same namespace and version twice is an error.
assert!(registry.register::<Lab>().is_err());Implementations§
Source§impl ExtensionRegistry
impl ExtensionRegistry
Sourcepub fn register<T: SigmfExtension>(&mut self) -> Result<(), SigmfError>
pub fn register<T: SigmfExtension>(&mut self) -> Result<(), SigmfError>
Registers support for extension T at its namespace and version.
§Errors
Returns SigmfError::InvalidMetadata if T’s namespace is empty or
"core", its version is empty, or the same namespace and version are
already registered.
Sourcepub fn supports(&self, namespace: &str, version: &str) -> bool
pub fn supports(&self, namespace: &str, version: &str) -> bool
Returns true if the extension namespace at version is registered.
Sourcepub fn supports_scope(
&self,
namespace: &str,
version: &str,
scope: ExtensionScope,
) -> bool
pub fn supports_scope( &self, namespace: &str, version: &str, scope: ExtensionScope, ) -> bool
Returns true if the registered extension namespace at version
applies to scope.
Returns false if the extension is not registered.
Sourcepub fn supports_field(
&self,
namespace: &str,
version: &str,
scope: ExtensionScope,
field: &str,
) -> bool
pub fn supports_field( &self, namespace: &str, version: &str, scope: ExtensionScope, field: &str, ) -> bool
Returns true if the registered extension namespace at version
applies to scope and defines the namespaced wire name field.
Returns false if the extension is not registered.
Sourcepub fn declarations(&self) -> Vec<ExtensionDeclaration>
pub fn declarations(&self) -> Vec<ExtensionDeclaration>
Returns a core:extensions declaration for each registered extension.
Declarations are sorted by namespace, then version, and are all marked
as required (optional: false).
Trait Implementations§
Source§impl Clone for ExtensionRegistry
impl Clone for ExtensionRegistry
Source§fn clone(&self) -> ExtensionRegistry
fn clone(&self) -> ExtensionRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExtensionRegistry
impl Debug for ExtensionRegistry
Source§impl Default for ExtensionRegistry
impl Default for ExtensionRegistry
Source§fn default() -> ExtensionRegistry
fn default() -> ExtensionRegistry
Auto Trait Implementations§
impl Freeze for ExtensionRegistry
impl RefUnwindSafe for ExtensionRegistry
impl Send for ExtensionRegistry
impl Sync for ExtensionRegistry
impl Unpin for ExtensionRegistry
impl UnsafeUnpin for ExtensionRegistry
impl UnwindSafe for ExtensionRegistry
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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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