telegram_bot_async_raw/requests/
leave_chat.rs

1use crate::{requests::*, types::*};
2
3/// Use this method for your bot to leave a group, supergroup or channel.
4#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
5#[must_use = "requests do nothing unless sent"]
6pub struct LeaveChat {
7    chat_id: ChatRef,
8}
9
10impl Request for LeaveChat {
11    type Type = JsonRequestType<Self>;
12    type Response = JsonTrueToUnitResponse;
13
14    fn serialize(&self) -> Result<HttpRequest, Error> {
15        Self::Type::serialize(RequestUrl::method("leaveChat"), self)
16    }
17}
18
19impl LeaveChat {
20    pub fn new<C>(chat: C) -> Self
21    where
22        C: ToChatRef,
23    {
24        LeaveChat {
25            chat_id: chat.to_chat_ref(),
26        }
27    }
28}
29
30/// Leave a group, supergroup or channel.
31pub trait CanLeaveChat {
32    fn leave(&self) -> LeaveChat;
33}
34
35impl<C> CanLeaveChat for C
36where
37    C: ToChatRef,
38{
39    fn leave(&self) -> LeaveChat {
40        LeaveChat::new(self)
41    }
42}