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
//! IPC command trait definition
use Cow;
use Future;
use ;
/// A type-safe IPC command with its handler
///
/// Users implement this trait to define commands that can be called from sandboxed processes.
/// The command struct contains the request data, and the `handle` method processes it.
///
/// # Example
///
/// ```rust,ignore
/// use std::borrow::Cow;
/// use serde::{Serialize, Deserialize};
/// use heel::ipc::IpcCommand;
///
/// #[derive(Clone, Serialize, Deserialize)]
/// struct SearchCommand {
/// query: String,
/// }
///
/// #[derive(Serialize, Deserialize)]
/// struct SearchResult {
/// items: Vec<String>,
/// }
///
/// impl IpcCommand for SearchCommand {
/// type Response = SearchResult;
///
/// fn name(&self) -> String {
/// "search".to_string()
/// }
///
/// fn positional_args(&self) -> Cow<'static, [Cow<'static, str>]> {
/// Cow::Borrowed(&[Cow::Borrowed("query")]) // Enables: search "rust" → search --query "rust"
/// }
///
/// fn apply_args(&mut self, params: &[u8]) -> Result<(), rmp_serde::decode::Error> {
/// *self = rmp_serde::from_slice(params)?;
/// Ok(())
/// }
///
/// async fn handle(&mut self) -> SearchResult {
/// let results = do_search(&self.query).await;
/// SearchResult { items: results }
/// }
/// }
/// ```