TriboolExt

Trait TriboolExt 

Source
pub trait TriboolExt<T> {
    // Required methods
    fn define(&self, default: Option<T>) -> Option<T>
       where T: Clone;
    fn apply_to_json(&self, obj: &mut Map<String, JsonValue>, key: &str) -> bool
       where T: Into<JsonValue> + Clone;
    fn apply_to_json_value(&self, obj: &mut JsonValue, key: &str) -> bool
       where T: Into<JsonValue> + Clone;
}
Expand description

Extension trait for Option that adds tribool-like functionality

Required Methods§

Source

fn define(&self, default: Option<T>) -> Option<T>
where T: Clone,

Define a value if the current value is None (undefined)

Similar to the tribool.define() function in C++, this method will set the value to the provided default only if the current value is None.

§Arguments
  • default - The value to use if self is None
§Returns

The existing value if Some, otherwise the default value

Source

fn apply_to_json(&self, obj: &mut Map<String, JsonValue>, key: &str) -> bool
where T: Into<JsonValue> + Clone,

Apply this tribool value to a JSON object if it’s defined (Some)

§Arguments
  • obj - The JSON object to modify
  • key - The key to set in the JSON object
§Returns

true if the value was applied, false if it was undefined (None)

Source

fn apply_to_json_value(&self, obj: &mut JsonValue, key: &str) -> bool
where T: Into<JsonValue> + Clone,

Apply this tribool value to a JSON Value object if it’s defined (Some)

§Arguments
  • obj - The JSON Value object to modify (must be an object type)
  • key - The key to set in the JSON object
§Returns

true if the value was applied, false if it was undefined (None) or the target wasn’t a JSON object

Implementations on Foreign Types§

Source§

impl<T> TriboolExt<T> for Option<T>

Source§

fn define(&self, default: Option<T>) -> Option<T>
where T: Clone,

Source§

fn apply_to_json(&self, obj: &mut Map<String, JsonValue>, key: &str) -> bool
where T: Into<JsonValue> + Clone,

Source§

fn apply_to_json_value(&self, obj: &mut JsonValue, key: &str) -> bool
where T: Into<JsonValue> + Clone,

Implementors§