pub trait Attributes {
// Required methods
fn attribute_names() -> &'static [&'static str];
fn read_attribute(&self, name: &str) -> Option<Value>;
fn write_attribute(
&mut self,
name: &str,
value: Value,
) -> Result<(), AttributeError>;
fn attributes(&self) -> HashMap<String, Value>;
// Provided methods
fn assign_attributes(
&mut self,
attrs: HashMap<String, Value>,
) -> Result<(), AttributeError> { ... }
fn has_attribute(name: &str) -> bool { ... }
}Expand description
Dynamic attribute access for model types.
Implementations bridge strongly typed Rust fields to serde_json::Value so
higher-level APIs can read and assign attributes generically.
Required Methods§
Sourcefn attribute_names() -> &'static [&'static str]
fn attribute_names() -> &'static [&'static str]
Returns the canonical list of attribute names for the model type.
Sourcefn read_attribute(&self, name: &str) -> Option<Value>
fn read_attribute(&self, name: &str) -> Option<Value>
Reads a single attribute as a dynamic JSON value.
Sourcefn write_attribute(
&mut self,
name: &str,
value: Value,
) -> Result<(), AttributeError>
fn write_attribute( &mut self, name: &str, value: Value, ) -> Result<(), AttributeError>
Writes a single attribute from a dynamic JSON value.
Sourcefn attributes(&self) -> HashMap<String, Value>
fn attributes(&self) -> HashMap<String, Value>
Returns every current attribute value keyed by its attribute name.
Provided Methods§
Sourcefn assign_attributes(
&mut self,
attrs: HashMap<String, Value>,
) -> Result<(), AttributeError>
fn assign_attributes( &mut self, attrs: HashMap<String, Value>, ) -> Result<(), AttributeError>
Assigns many attributes by delegating to Attributes::write_attribute.
Sourcefn has_attribute(name: &str) -> bool
fn has_attribute(name: &str) -> bool
Returns true when the provided attribute name belongs to the model.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.