1use serde::{Deserialize, Serialize};
2
3use crate::Result;
4
5use super::request;
6
7#[derive(Debug, Serialize, Deserialize)]
8struct ManageState<D> {
9 operation: &'static str,
10 #[serde(rename = "newState")]
11 state: Option<D>,
12}
13
14#[derive(Debug, Serialize, Deserialize)]
15struct ManageStateBare {
16 operation: &'static str,
17}
18
19pub async fn state_update<D>(state: D) -> Result<()>
25where
26 D: Serialize,
27{
28 let arg = ManageState {
29 operation: "update",
30 state: Some(state),
31 };
32
33 request("snap_manageState", arg).await?;
34
35 Ok(())
36}
37
38pub async fn state_clear() -> Result<()> {
44 request("snap_manageState", ManageStateBare { operation: "clear" }).await?;
45
46 Ok(())
47}
48
49pub async fn state_get<D>() -> Result<D>
55where
56 D: for<'de> Deserialize<'de>,
57{
58 Ok(request("snap_manageState", ManageStateBare { operation: "get" }).await?)
59}