mirror of
https://github.com/xai-org/x-algorithm.git
synced 2026-02-13 03:05:06 +01:00
23 lines
520 B
Rust
23 lines
520 B
Rust
use std::any::{Any, type_name_of_val};
|
|
use tonic::async_trait;
|
|
|
|
use crate::util;
|
|
|
|
#[async_trait]
|
|
pub trait Source<Q, C>: Any + Send + Sync
|
|
where
|
|
Q: Clone + Send + Sync + 'static,
|
|
C: Clone + Send + Sync + 'static,
|
|
{
|
|
/// Decide if this source should run for the given query
|
|
fn enable(&self, _query: &Q) -> bool {
|
|
true
|
|
}
|
|
|
|
async fn get_candidates(&self, query: &Q) -> Result<Vec<C>, String>;
|
|
|
|
fn name(&self) -> &'static str {
|
|
util::short_type_name(type_name_of_val(self))
|
|
}
|
|
}
|