Trait libreda_db::property_storage::WithProperties

source ·
pub trait WithProperties {
    type Key: Hash + Eq;

    // Required methods
    fn with_properties<F, R>(&self, f: F) -> R
       where F: FnOnce(Option<&PropertyStore<Self::Key>>) -> R;
    fn with_properties_mut<F, R>(&self, f: F) -> R
       where F: FnOnce(&mut PropertyStore<Self::Key>) -> R;

    // Provided methods
    fn property<Q>(&self, key: &Q) -> Option<PropertyValue>
       where Self::Key: Borrow<Q>,
             Q: Eq + Hash + ?Sized { ... }
    fn property_str<Q>(&self, key: &Q) -> Option<RcString>
       where Self::Key: Borrow<Q>,
             Q: Eq + Hash + ?Sized { ... }
    fn set_property<V: Into<PropertyValue>>(
        &self,
        key: Self::Key,
        value: V,
    ) -> Option<PropertyValue> { ... }
}
Expand description

A trait for associating user defined properties with a type.

Required Associated Types§

source

type Key: Hash + Eq

Property key type.

Required Methods§

source

fn with_properties<F, R>(&self, f: F) -> R
where F: FnOnce(Option<&PropertyStore<Self::Key>>) -> R,

Call a function with maybe the property storage as argument.

The property store might not always be initialized. For instance for objects without any defined properties, it will likely be None.

source

fn with_properties_mut<F, R>(&self, f: F) -> R
where F: FnOnce(&mut PropertyStore<Self::Key>) -> R,

Get mutable reference to the property storage.

Provided Methods§

source

fn property<Q>(&self, key: &Q) -> Option<PropertyValue>
where Self::Key: Borrow<Q>, Q: Eq + Hash + ?Sized,

Get a property value by the property key.

source

fn property_str<Q>(&self, key: &Q) -> Option<RcString>
where Self::Key: Borrow<Q>, Q: Eq + Hash + ?Sized,

Get a string property value by key. If the property value is not a string None is returned.

source

fn set_property<V: Into<PropertyValue>>( &self, key: Self::Key, value: V, ) -> Option<PropertyValue>

Insert a property. Returns the old property value if there was already a property stored under this key.

Object Safety§

This trait is not object safe.

Implementors§