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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
mod hooks;
use async_trait::async_trait;
#[cfg(feature = "cache")]
use std::rc::Rc;
#[cfg(feature = "cache")]
use yewdux::store::Store;
pub use hooks::*;
pub mod prelude {
pub use crate::{hooks::*, Request};
pub use async_trait::async_trait;
#[cfg(feature = "cache")]
pub use crate::CachableRequest;
#[cfg(feature = "cache")]
pub use std::rc::Rc;
#[cfg(feature = "cache")]
pub use yewdux::store::Store;
}
#[async_trait(?Send)]
pub trait Request: std::fmt::Debug + PartialEq + Clone {
type Error: Clone + std::fmt::Debug + PartialEq + 'static;
type Output: Clone + std::fmt::Debug + PartialEq + 'static;
async fn run(&self) -> Result<Self::Output, Self::Error>;
fn store(_: Self::Output) {}
}
#[cfg(feature = "cache")]
pub trait CachableRequest: Request {
type Store: Store + PartialEq;
fn load(&self, store: Rc<Self::Store>) -> Option<Self::Output>;
}