girolle/rpc_task.rs
1use crate::types::NamekoFunction;
2/// # RpcTask
3///
4/// ## Description
5///
6/// This struct is used to create a RPC task. This task will be used to register
7/// a function in the RpcService struct.
8///
9/// ## Example
10///
11/// ```rust,no_run
12/// use girolle::prelude::*;
13/// use std::vec;
14///
15/// fn hello(s: &[Value]) -> GirolleResult<Value> {
16/// // Parse the incomming data
17/// let n: String = serde_json::from_value(s[0].clone())?;
18/// let hello_str: Value = format!("Hello, {}!, by Girolle", n).into();
19/// Ok(hello_str)
20/// }
21///
22///
23/// fn main() {
24/// let mut services: RpcService = RpcService::new(Config::default_config(),"video");
25/// let rpc_task = RpcTask::new("hello", vec!["s"], hello);
26/// }
27///
28#[derive(Clone)]
29pub struct RpcTask {
30 pub name: &'static str,
31 pub args: Vec<&'static str>,
32 pub inner_function: NamekoFunction,
33}
34impl RpcTask {
35 /// # new
36 ///
37 /// ## Description
38 ///
39 /// This function create a new RpcTask struct
40 ///
41 /// ## Arguments
42 ///
43 /// * `name` - The name of the function to call
44 /// * `inner_function` - The function to call as NamekoFunction
45 ///
46 /// ## Returns
47 ///
48 /// This function return a girolle::RpcTask struct
49 ///
50 /// ## Example
51 ///
52 /// ```rust,no_run
53 /// use girolle::prelude::*;
54 /// use std::vec;
55 ///
56 /// fn hello(s: &[Value]) -> GirolleResult<Value> {
57 /// // Parse the incomming data
58 /// let n: String = serde_json::from_value(s[0].clone())?;
59 /// let hello_str: Value = format!("Hello, {}!, by Girolle", n).into();
60 /// Ok(hello_str)
61 /// }
62 ///
63 /// fn main() {
64 /// let mut services: RpcService = RpcService::new(Config::default_config(),"video");
65 /// let rpc_task = RpcTask::new("hello", vec!["s"], hello);
66 /// }
67 ///
68 pub fn new(
69 name: &'static str,
70 args: Vec<&'static str>,
71 inner_function: NamekoFunction,
72 ) -> Self {
73 Self {
74 name,
75 args,
76 inner_function,
77 }
78 }
79}