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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use async_trait;
use Hash;
use Rc;
use crateBounceStates;
/// A Result returned by queries.
pub type QueryResult<T> = Result;
/// A trait to be implemented on queries.
///
/// # Note
///
/// This trait is implemented with [async_trait](macro@async_trait), you should apply an `#[async_trait(?Send)]`
/// attribute to your implementation of this trait.
///
/// # Example
///
/// ```
/// use std::rc::Rc;
/// use std::convert::Infallible;
/// use bounce::prelude::*;
/// use bounce::query::{Query, QueryResult};
/// use yew::prelude::*;
/// use async_trait::async_trait;
///
/// #[derive(Debug, PartialEq)]
/// struct User {
/// id: u64,
/// name: String,
/// }
///
/// #[derive(Debug, PartialEq)]
/// struct UserQuery {
/// value: User
/// }
///
/// #[async_trait(?Send)]
/// impl Query for UserQuery {
/// type Input = u64;
/// type Error = Infallible;
///
/// async fn query(_states: &BounceStates, input: Rc<u64>) -> QueryResult<Self> {
/// // fetch user
///
/// Ok(UserQuery{ value: User { id: *input, name: "John Smith".into() } }.into())
/// }
/// }
/// ```
///
/// See: [`use_query`](super::use_query()) and [`use_query_value`](super::use_query_value())
/// A Result returned by mutations.
pub type MutationResult<T> = Result;
/// A trait to be implemented on mutations.
///
/// # Note
///
/// This trait is implemented with [async_trait](macro@async_trait), you should apply an `#[async_trait(?Send)]`
/// attribute to your implementation of this trait.
///
/// # Example
///
/// ```
/// use std::rc::Rc;
/// use std::convert::Infallible;
/// use bounce::prelude::*;
/// use bounce::query::{Mutation, MutationResult};
/// use yew::prelude::*;
/// use async_trait::async_trait;
///
/// #[derive(Debug, PartialEq)]
/// struct User {
/// id: u64,
/// name: String,
/// }
///
/// #[derive(Debug, PartialEq)]
/// struct UpdateUserMutation {
/// }
///
/// #[async_trait(?Send)]
/// impl Mutation for UpdateUserMutation {
/// type Input = User;
/// type Error = Infallible;
///
/// async fn run(_states: &BounceStates, _input: Rc<User>) -> MutationResult<Self> {
/// // updates the user information.
///
/// Ok(UpdateUserMutation {}.into())
/// }
/// }
/// ```
///
/// See: [`use_mutation`](super::use_mutation())