Skip to main content

Attributes

Trait Attributes 

Source
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§

Source

fn attribute_names() -> &'static [&'static str]

Returns the canonical list of attribute names for the model type.

Source

fn read_attribute(&self, name: &str) -> Option<Value>

Reads a single attribute as a dynamic JSON value.

Source

fn write_attribute( &mut self, name: &str, value: Value, ) -> Result<(), AttributeError>

Writes a single attribute from a dynamic JSON value.

Source

fn attributes(&self) -> HashMap<String, Value>

Returns every current attribute value keyed by its attribute name.

Provided Methods§

Source

fn assign_attributes( &mut self, attrs: HashMap<String, Value>, ) -> Result<(), AttributeError>

Assigns many attributes by delegating to Attributes::write_attribute.

Source

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.

Implementors§