Feature

Trait Feature 

Source
pub trait Feature {
    // Required methods
    fn get_name(&self) -> Result<String>;
    fn is_enabled(&self) -> Result<bool>;
    fn get_value(&self, entity: &impl Entity) -> Result<Value>;
    fn get_value_into<T: TryFrom<Value, Error = Error>>(
        &self,
        entity: &impl Entity,
    ) -> Result<T>;
}
Expand description

Access to data and evaluation of IBM AppConfiguration features

Required Methods§

Source

fn get_name(&self) -> Result<String>

Returns the full name of the feature.

Source

fn is_enabled(&self) -> Result<bool>

Returns if the feature is enabled or not.

An enabled feature should be evaluated for each Entity to get the corresponding value. However, disabled features won’t be evaluated and will always return the disabled value.

Source

fn get_value(&self, entity: &impl Entity) -> Result<Value>

Evaluates a feature for the given Entity and returns a Value.

Use the methods available in Value to return the actual primitive value. If all you want is the primitive value, you can use the method get_value_into instead.

§Examples
    let feature = client.get_feature("my_feature")?;
    let value: Value = feature.get_value(entity)?;

    match value {
        Value::Float64(v) => println!("f64 with value {v}"),
        Value::UInt64(v) => println!("u64 with value {v}"),
        Value::Int64(v) => println!("i64 with value {v}"),
        Value::String(v) => println!("String with value {v}"),
        Value::Boolean(v) => println!("bool with value {v}"),
    }
Source

fn get_value_into<T: TryFrom<Value, Error = Error>>( &self, entity: &impl Entity, ) -> Result<T>

Evaluates a feature for the given Entity and returns its value converted (if possible) to the given type.

§Examples
    let feature = client.get_feature("my_f64_feature")?;
    let value: f64 = feature.get_value_into(entity)?;

    // an f64 cannot be returned as u64
    let failed: Result<u64> = feature.get_value_into(entity);
    assert!(failed.is_err());

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§