forked from xai-org/x-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_hydrator.rs
More file actions
27 lines (22 loc) · 784 Bytes
/
query_hydrator.rs
File metadata and controls
27 lines (22 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::any::{Any, type_name_of_val};
use tonic::async_trait;
use crate::util;
#[async_trait]
pub trait QueryHydrator<Q>: Any + Send + Sync
where
Q: Clone + Send + Sync + 'static,
{
/// Decide if this query hydrator should run for the given query
fn enable(&self, _query: &Q) -> bool {
true
}
/// Hydrate the query by performing async operations.
/// Returns a new query with this hydrator's fields populated.
async fn hydrate(&self, query: &Q) -> Result<Q, String>;
/// Update the query with the hydrated fields.
/// Only the fields this hydrator is responsible for should be copied.
fn update(&self, query: &mut Q, hydrated: Q);
fn name(&self) -> &'static str {
util::short_type_name(type_name_of_val(self))
}
}