rlay_backend/
lib.rs

1#[cfg(feature = "rpc")]
2pub mod rpc;
3
4use async_trait::async_trait;
5// use futures::future::FutureExt;
6// use futures::prelude::*;
7use rlay_ontology::ontology::Entity;
8use std::collections::HashMap;
9use std::future::Future;
10
11pub use failure::Error;
12pub use futures::future::BoxFuture;
13#[cfg(feature = "rpc")]
14pub use rpc::BackendRpcMethods;
15
16#[async_trait]
17pub trait GetEntity {
18    async fn get_entity(&self, cid: &[u8]) -> Result<Option<Entity>, Error>;
19}
20
21// impl<'a> GetEntity<'a> for std::collections::BTreeMap<&[u8], Entity> {
22// type F = BoxFuture<'a, Result<Option<Entity>, Error>>;
23
24// fn get_entity(&'a self, cid: &[u8]) -> Self::F {
25// future::ready(Ok(self.get(cid).map(|n| n.to_owned()))).boxed()
26// }
27// }
28
29#[async_trait]
30pub trait ResolveEntity {
31    async fn resolve_entity(&self, cid: &[u8]) -> Result<HashMap<Vec<u8>, Vec<Entity>>, Error>;
32}
33
34pub trait BackendFromConfigAndSyncState: Sized {
35    type C;
36    type S;
37    type R: Future<Output = Result<Self, Error>> + Send;
38
39    fn from_config_and_syncstate(config: Self::C, sync_state: Self::S) -> Self::R;
40}