io_gmail/v1/rest/threads/
trash.rs1use alloc::{format, vec::Vec};
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12 coroutine::*,
13 gmail_try,
14 v1::rest::threads::GmailThread,
15 v1::send::{GMAIL_API_BASE, GmailSend, GmailSendError, GmailSendOutput},
16};
17
18pub struct GmailThreadTrash {
20 send: GmailSend<GmailThread>,
21}
22
23impl GmailThreadTrash {
24 pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, GmailSendError> {
26 debug!("prepare gmail thread trashing");
27 trace!("id: {id:?}");
28
29 let url =
30 Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/threads/{id}/trash"))?;
31 let send = GmailSend::with_method(auth, "POST", url, None, Vec::new());
32
33 Ok(Self { send })
34 }
35}
36
37impl GmailCoroutine for GmailThreadTrash {
38 type Yield = GmailYield;
39 type Return = Result<GmailSendOutput<GmailThread>, GmailSendError>;
40
41 fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
42 let out = gmail_try!(&mut self.send, arg);
43 debug!("thread trashed");
44 trace!("out: {out:?}");
45 GmailCoroutineState::Complete(Ok(out))
46 }
47}