pub struct Query {
pub event_type: Option<EventType>,
pub conditions: Vec<Condition>,
}Expand description
A structured query for use in interacting with the Tendermint RPC event subscription system.
Allows for compile-time validation of queries.
See the subscribe endpoint documentation for more details.
§Examples
§Direct construction of queries
use tendermint_rpc::query::{Query, EventType};
let query = Query::from(EventType::NewBlock);
assert_eq!("tm.event = 'NewBlock'", query.to_string());
let query = Query::from(EventType::Tx).and_eq("tx.hash", "XYZ");
assert_eq!("tm.event = 'Tx' AND tx.hash = 'XYZ'", query.to_string());
let query = Query::from(EventType::Tx).and_gte("tx.height", 100_u64);
assert_eq!("tm.event = 'Tx' AND tx.height >= 100", query.to_string());§Query parsing
use tendermint_rpc::query::{Query, EventType};
let query: Query = "tm.event = 'NewBlock'".parse().unwrap();
assert_eq!(query, Query::from(EventType::NewBlock));
let query: Query = "tm.event = 'Tx' AND tx.hash = 'XYZ'".parse().unwrap();
assert_eq!(query, Query::from(EventType::Tx).and_eq("tx.hash", "XYZ"));
let query: Query = "tm.event = 'Tx' AND tx.height >= 100".parse().unwrap();
assert_eq!(query, Query::from(EventType::Tx).and_gte("tx.height", 100_u64));Fields§
§event_type: Option<EventType>§conditions: Vec<Condition>Implementations§
Source§impl Query
impl Query
Sourcepub fn eq(key: impl ToString, value: impl Into<Operand>) -> Self
pub fn eq(key: impl ToString, value: impl Into<Operand>) -> Self
Query constructor testing whether <key> = <value>
Sourcepub fn lt(key: impl ToString, value: impl Into<Operand>) -> Self
pub fn lt(key: impl ToString, value: impl Into<Operand>) -> Self
Query constructor testing whether <key> < <value>
Sourcepub fn lte(key: impl ToString, value: impl Into<Operand>) -> Self
pub fn lte(key: impl ToString, value: impl Into<Operand>) -> Self
Query constructor testing whether <key> <= <value>
Sourcepub fn gt(key: impl ToString, value: impl Into<Operand>) -> Self
pub fn gt(key: impl ToString, value: impl Into<Operand>) -> Self
Query constructor testing whether <key> > <value>
Sourcepub fn gte(key: impl ToString, value: impl Into<Operand>) -> Self
pub fn gte(key: impl ToString, value: impl Into<Operand>) -> Self
Query constructor testing whether <key> >= <value>
Sourcepub fn contains(key: impl ToString, value: impl ToString) -> Self
pub fn contains(key: impl ToString, value: impl ToString) -> Self
Query constructor testing whether <key> CONTAINS <value> (assuming
key contains a string, this tests whether value is a sub-string
within it).
Sourcepub fn and_eq(self, key: impl ToString, value: impl Into<Operand>) -> Self
pub fn and_eq(self, key: impl ToString, value: impl Into<Operand>) -> Self
Add the condition <key> = <value> to the query.
Sourcepub fn and_lt(self, key: impl ToString, value: impl Into<Operand>) -> Self
pub fn and_lt(self, key: impl ToString, value: impl Into<Operand>) -> Self
Add the condition <key> < <value> to the query.
Sourcepub fn and_lte(self, key: impl ToString, value: impl Into<Operand>) -> Self
pub fn and_lte(self, key: impl ToString, value: impl Into<Operand>) -> Self
Add the condition <key> <= <value> to the query.
Sourcepub fn and_gt(self, key: impl ToString, value: impl Into<Operand>) -> Self
pub fn and_gt(self, key: impl ToString, value: impl Into<Operand>) -> Self
Add the condition <key> > <value> to the query.
Sourcepub fn and_gte(self, key: impl ToString, value: impl Into<Operand>) -> Self
pub fn and_gte(self, key: impl ToString, value: impl Into<Operand>) -> Self
Add the condition <key> >= <value> to the query.
Sourcepub fn and_contains(self, key: impl ToString, value: impl ToString) -> Self
pub fn and_contains(self, key: impl ToString, value: impl ToString) -> Self
Add the condition <key> CONTAINS <value> to the query.
Sourcepub fn and_exists(self, key: impl ToString) -> Self
pub fn and_exists(self, key: impl ToString) -> Self
Add the condition <key> EXISTS to the query.
Trait Implementations§
Source§impl Default for Query
impl Default for Query
Source§fn default() -> Self
fn default() -> Self
An empty query matches any set of events. See these docs.