Skip to main content

io_gmail/v1/rest/labels/
delete.rs

1//! Delete a Gmail label (`users.labels.delete`).
2//!
3//! <https://developers.google.com/gmail/api/reference/rest/v1/users.labels/delete>
4
5use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use url::Url;
10
11use crate::{
12    coroutine::*,
13    gmail_try,
14    v1::send::{GMAIL_API_BASE, GmailNoResponse, GmailSend, GmailSendError, GmailSendOutput},
15};
16
17/// I/O-free coroutine deleting a Gmail label by id (`users.labels.delete`).
18pub struct GmailLabelDelete {
19    send: GmailSend<GmailNoResponse>,
20}
21
22impl GmailLabelDelete {
23    /// Builds the `users.labels.delete` request for the given label id.
24    pub fn new(auth: &HttpAuthBearer, user_id: &str, id: &str) -> Result<Self, GmailSendError> {
25        debug!("prepare gmail label deletion");
26        trace!("id: {id:?}");
27
28        let url = Url::parse(GMAIL_API_BASE)?.join(&format!("users/{user_id}/labels/{id}"))?;
29        let send = GmailSend::delete(auth, url);
30
31        Ok(Self { send })
32    }
33}
34
35impl GmailCoroutine for GmailLabelDelete {
36    type Yield = GmailYield;
37    type Return = Result<GmailSendOutput<GmailNoResponse>, GmailSendError>;
38
39    fn resume(&mut self, arg: Option<&[u8]>) -> GmailCoroutineState<Self::Yield, Self::Return> {
40        let out = gmail_try!(&mut self.send, arg);
41        debug!("label deleted");
42        trace!("out: {out:?}");
43        GmailCoroutineState::Complete(Ok(out))
44    }
45}