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-levelValue -> 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 aStixObject::Custom.
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn register_handler<F>(&mut self, type_name: impl Into<String>, hook: F)
pub fn register_handler<F>(&mut self, type_name: impl Into<String>, hook: F)
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.
Sourcepub fn register<T>(&mut self, type_name: impl Into<String>)where
T: DeserializeOwned + CustomObject + 'static,
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).
Sourcepub fn parse_object(&self, value: Value) -> Result<StixObject>
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.
Sourcepub fn parse_bundle(&self, json: &str) -> Result<Bundle>
pub fn parse_bundle(&self, json: &str) -> Result<Bundle>
Parse a bundle, routing every object through parse_object.