pub struct Condition { /* private fields */ }
Expand description

Representation of an Aspen condition clause in a statement.

This is (logically and physically) a two-level map. The first level (this structure) maps ConditionOp operators to a ConditionMap. The second level, the ConditionMap itself, maps condition variable names to a list of allowed values.

Implementations§

Create a new condition clause with no values.

Moves all elements from other into self, leaving other empty.

Examples

let mut a = Condition::new();
a.insert(condop::StringEquals, ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]));

let mut b = Condition::new();
b.insert(condop::StringLike, ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]));

a.append(&mut b);

assert_eq!(a.len(), 2);
assert_eq!(b.len(), 0);

Clears the condition clause, removing all elements.

Examples

Basic usage:


let mut a = Condition::new();
a.insert(condop::StringEquals, ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]));
a.clear();
assert!(a.is_empty());

Returns true if the condition clause contains a value for the specified ConditionOp operator.

Examples

Basic usage:


let mut condition = Condition::new();
condition.insert(condop::StringEquals, ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]));
assert_eq!(condition.contains_key(&condop::StringEquals), true);
assert_eq!(condition.contains_key(&condop::NumericEquals), false);

Gets the given ConditionOp operator’s corresponding entry in the map for in-place manipulation.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
condition.insert(condop::StringEquals, cmap);
condition.entry(condop::StringEquals).and_modify(|e| {
    e.insert("b".to_string(), StringLikeList::<String>::from("B".to_string()));
});

assert_eq!(condition.get(&condop::StringEquals).unwrap().len(), 2);

Returns a reference to the ConditionMap corresponding to the ConditionOp operator.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
condition.insert(condop::StringEquals, cmap.clone());
assert_eq!(condition.get(&condop::StringEquals), Some(&cmap));
assert_eq!(condition.get(&condop::StringLike), None);

Returns the (ConditionOp, ConditionMap) key-value pair corresponding to the supplied ConditionOp operator.

Examples

let mut condition = Condition::new();
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
condition.insert(condop::StringEquals, cmap.clone());
assert_eq!(condition.get_key_value(&condop::StringEquals), Some((&condop::StringEquals, &cmap)));
assert_eq!(condition.get_key_value(&condop::StringLike), None);

Returns a mutable reference to the ConditionMap corresponding to the ConditionOp operator.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
condition.insert(condop::StringEquals, cmap1);
if let Some(x) = condition.get_mut(&condop::StringEquals) {
    *x = cmap2.clone();
}
assert_eq!(condition[&condop::StringEquals], cmap2);

Inserts a key-value pair into the Condition clause.

If the clause did not have this operator present, None is returned.

If the clause did have this operator present, the value is updated, and the old value is returned.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);

assert_eq!(condition.insert(condop::StringEquals, cmap1.clone()), None);
assert_eq!(condition.insert(condop::StringEquals, cmap2.clone()), Some(cmap1));

Creates a consuming iterator visiting all the ConditionOp operators, in sorted order. The map cannot be used after calling this.

Examples

let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
condition.insert(condop::StringEquals, cmap1);
condition.insert(condop::StringEqualsIgnoreCase, cmap2);

let keys: Vec<ConditionOp> = condition.into_keys().collect();
assert_eq!(keys, [condop::StringEquals, condop::StringEqualsIgnoreCase]);

Creates a consuming iterator visiting all the values, in order by the ConditionOp operator. The map cannot be used after calling this.

Examples

let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
condition.insert(condop::StringEquals, cmap1.clone());
condition.insert(condop::StringEqualsIgnoreCase, cmap2.clone());

let values: Vec<ConditionMap> = condition.into_values().collect();
assert_eq!(values, [cmap1, cmap2]);

Returns true if the condition clause contains no elements.

Examples

Basic usage:


let mut condition = Condition::new();
assert!(condition.is_empty());
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
condition.insert(condop::StringEquals, cmap);
assert!(!condition.is_empty());

Gets an iterator over the (&ConditionOp, &ConditionMap) entries of the condition clause, sorted by ConditionOp operator.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::Bool, cmap2.clone());
condition.insert(condop::ArnLike, cmap1.clone());
condition.insert(condop::StringEquals, cmap3.clone());

let values: Vec<(&ConditionOp, &ConditionMap)> = condition.iter().collect();
assert_eq!(values, vec![(&condop::ArnLike, &cmap1), (&condop::Bool, &cmap2), (&condop::StringEquals, &cmap3)]);

Gets an mutable iterator over the (&ConditionOp, &mut ConditionMap) entries of the condition clause, sorted by ConditionOp operator.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::Bool, cmap2.clone());
condition.insert(condop::ArnLike, cmap1.clone());
condition.insert(condop::StringEquals, cmap3.clone());

let values: Vec<(&ConditionOp, &ConditionMap)> = condition.iter().collect();
// Add a new variable to the Bool operator.
for (key, value) in condition.iter_mut() {
    if key == &condop::Bool {
       value.insert("d".to_string(), StringLikeList::<String>::from("D".to_string()));
    }
}

Gets an iterator over the ConditionOp operator keys of the map, in sorted order.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::Bool, cmap2.clone());
condition.insert(condop::ArnLike, cmap1.clone());
condition.insert(condop::StringEquals, cmap3.clone());

let keys: Vec<ConditionOp> = condition.keys().cloned().collect();
assert_eq!(keys, [condop::ArnLike, condop::Bool, condop::StringEquals]);

Returns the number of elements in the condition clause.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
assert_eq!(condition.len(), 0);
condition.insert(condop::StringEquals, cmap);
assert_eq!(condition.len(), 1);

Constructs a double-ended iterator over a sub-range of elements in the condition clause. The simplest way is to use the range syntax min..max, thus range(min..max) will yield elements from min (inclusive) to max (exclusive). The range may also be entered as (Bound<T>, Bound<T>), so for example range((Excluded(condop::ArnLike), Included(condop::StringEquals))) will yield a left-exclusive, right-inclusive range.

Panics

Panics if range start > end. Panics if range start == end and both bounds are Excluded.

Examples

Basic usage:

use std::ops::Bound::Included;

let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::ArnLike, cmap1.clone());
condition.insert(condop::Bool, cmap2.clone());
condition.insert(condop::StringEquals, cmap3.clone());

let result: Vec<(&ConditionOp, &ConditionMap)> = condition.range((Included(condop::Bool), Included(condop::NumericEquals))).collect();
assert_eq!(result, vec![(&condop::Bool, &cmap2)]);

Constructs a mutable double-ended iterator over a sub-range of elements in the condition clause. The simplest way is to use the range syntax min..max, thus range(min..max) will yield elements from min (inclusive) to max (exclusive). The range may also be entered as (Bound<T>, Bound<T>), so for example range((Excluded(condop::ArnLike), Included(condop::StringEquals))) will yield a left-exclusive, right-inclusive range.

Panics

Panics if range start > end. Panics if range start == end and both bounds are Excluded.

Examples

Basic usage:

use std::ops::Bound::Included;

let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::ArnLike, cmap1);
condition.insert(condop::Bool, cmap2);
condition.insert(condop::StringEquals, cmap3);

for (_, cmap) in condition.range_mut((Included(condop::Bool), Included(condop::NumericEquals))) {
    cmap.insert("d".to_string(), StringLikeList::<String>::from("D".to_string()));
}

assert_eq!(condition.get(&condop::Bool).unwrap().len(), 2);

Removes a ConditionOp operator from the condition clause, returning the ConditionMap corresponding to the operator if the operator was previously in the clause.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);

condition.insert(condop::Bool, cmap.clone());

assert_eq!(condition.remove(&condop::Bool), Some(cmap));
assert_eq!(condition.remove(&condop::Bool), None);
source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(ConditionOp, ConditionMap)>where
    ConditionOp: Borrow<Q>,
    Q: Ord + ?Sized,

Removes a ConditionOp operator from the condition clause, returning the stored operator and ConditionMap if the operator was previously in the clause.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);

condition.insert(condop::Bool, cmap.clone());

assert_eq!(condition.remove_entry(&condop::Bool), Some((condop::Bool, cmap)));
assert_eq!(condition.remove(&condop::Bool), None);

Retains only the elements specified by the predicate.

In other words, remove all pairs (cond_op, cond_map) for which f(&cond_op, &mut cond_map) returns false. The elements are visited in ascending ConditionOp order.

Examples

let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::ArnLike, cmap1);
condition.insert(condop::Bool, cmap2.clone());
condition.insert(condop::StringEquals, cmap3);

// Keep only the Bool key.
condition.retain(|&k, _| k == condop::Bool);
assert!(condition.into_iter().eq(vec![(condop::Bool, cmap2)]));

Splits the collection into two at the given ConditionOp operator. Returns everything on and after the given ConditionOp.

Examples

let mut a = Condition::new();
let cmap = ConditionMap::new();

a.insert(condop::ArnLike, cmap.clone());
a.insert(condop::Bool, cmap.clone());
a.insert(condop::DateEquals, cmap.clone());
a.insert(condop::NumericEquals, cmap.clone());
a.insert(condop::StringEquals, cmap.clone());

let b= a.split_off(&condop::DateEquals);
assert_eq!(a.len(), 2);
assert_eq!(b.len(), 3);

assert_eq!(a.into_keys().collect::<Vec<_>>(), vec![condop::ArnLike, condop::Bool]);
assert_eq!(b.into_keys().collect::<Vec<_>>(), vec![condop::DateEquals, condop::NumericEquals, condop::StringEquals]);

Gets an iterator over the ConditionMap values of the map, in order by ConditionOp key.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::Bool, cmap2.clone());
condition.insert(condop::ArnLike, cmap1.clone());
condition.insert(condop::StringEquals, cmap3.clone());

let values: Vec<ConditionMap> = condition.values().cloned().collect();
assert_eq!(values, [cmap1, cmap2, cmap3]);

Gets an iterator over the mutable ConditionMap values of the map, in order by ConditionOp key.

Examples

Basic usage:


let mut condition = Condition::new();
let cmap1 = ConditionMap::from_iter(vec![("a".to_string(), StringLikeList::<String>::from("A".to_string()))]);
let cmap2 = ConditionMap::from_iter(vec![("b".to_string(), StringLikeList::<String>::from("B".to_string()))]);
let cmap3 = ConditionMap::from_iter(vec![("c".to_string(), StringLikeList::<String>::from("C".to_string()))]);

condition.insert(condop::Bool, cmap2);
condition.insert(condop::ArnLike, cmap1);
condition.insert(condop::StringEquals, cmap3);

for value in condition.values_mut() {
   value.insert("d".to_string(), StringLikeList::<String>::from("D".to_string()));
}

assert_eq!(condition.get(&condop::ArnLike).unwrap().len(), 2);

Indicates whether this condition clause matches the request Context. This condition is interpreted using the specified PolicyVersion.

Errors

If a condition clause contains a malformed variable, AspenError::InvalidSubstitution is returned.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Converts to this type from the input type.
Creates a value from an iterator. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.