pub fn map_key<I: Iterator>(xs: I) -> MapKeyIter<I>ⓘNotable traits for MapKeyIter<I>impl<I> Iterator for MapKeyIter<I> where
I: Iterator,
I::Item: Keyed, type Item = <I::Item as Keyed>::Key;
Expand description
Takes a list of entities and turn them into keys. This can also be used to create key predicates.
Example
- Basic collection of keys
- Building a key predicate for a Toql query
ⓘ
use toql_derive::Toql;
use toql_core::{map_key::MapKey, query::Query};
#[derive(Toql)]
struct User {
#[toql(key)]
id: u64,
name: String
}
let users = vec![User{id:5, name: "Joe".to_string()}, User{id:7, name: "Sue".to_string()}];
let keys = users.iter().map_key().collect::<Vec<_>>(); // Returns Vec<UserKey>
let predicate = users.iter().map_key().collect::<Query>(); // Build query
assert_eq!(predicate.to_string, "(id eq 5;id eq 7)");
Notice that when keys are be collected into a Query the predicates are concatenated with OR.