Skip to main content

ModelRegistry

Struct ModelRegistry 

Source
pub struct ModelRegistry { /* private fields */ }
Expand description

Maps a STIX type to a consumer-supplied handler. Registered handlers take precedence over the built-in dispatch in StixObject::from_json.

Two registration forms:

  • register_handler: a data-level Value -> Result<Value> validate/normalize hook (the form bindings bridge a host callable onto). The result is stored as a generic object.
  • register: a typed Rust convenience that stores a StixObject::Custom.

Implementations§

Source§

impl ModelRegistry

Source

pub fn new() -> Self

An empty registry (parsing behaves like the built-in dispatch).

Source

pub fn register_handler<F>(&mut self, type_name: impl Into<String>, hook: F)
where F: Fn(Value) -> Result<Value> + Send + Sync + 'static,

Register a data-level validate/normalize hook for type_name. The hook may reject the object (return Err) or return an enriched object (e.g. with a computed property). The result is stored as a StixObject::Generic.

Source

pub fn register<T>(&mut self, type_name: impl Into<String>)
where T: DeserializeOwned + CustomObject + 'static,

Register a typed Rust struct for type_name. Objects of that type deserialize into T and are stored as StixObject::Custom, retrievable with StixObject::downcast_ref. T only needs to implement ObjectView (plus Serialize/Deserialize).

Source

pub fn parse_object(&self, value: Value) -> Result<StixObject>

Parse a single JSON object, dispatching on its type: a registered handler wins; otherwise the built-in dispatch applies.

Source

pub fn parse_bundle(&self, json: &str) -> Result<Bundle>

Parse a bundle, routing every object through parse_object.

Trait Implementations§

Source§

impl Default for ModelRegistry

Source§

fn default() -> ModelRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.