async_imap/types/
response_data.rs1#![allow(missing_docs)]
2
3use std::fmt;
4
5use bytes::BytesMut;
6use imap_proto::{RequestId, Response};
7use self_cell::self_cell;
8
9self_cell!(
10 pub struct ResponseData {
11 owner: BytesMut,
12
13 #[covariant]
14 dependent: Response,
15 }
16);
17
18impl std::cmp::PartialEq for ResponseData {
19 fn eq(&self, other: &Self) -> bool {
20 self.parsed() == other.parsed()
21 }
22}
23
24impl std::cmp::Eq for ResponseData {}
25
26impl fmt::Debug for ResponseData {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.debug_struct("ResponseData")
29 .field("raw", &self.borrow_owner().len())
30 .field("response", self.borrow_dependent())
31 .finish()
32 }
33}
34
35impl ResponseData {
36 pub fn raw(&self) -> &[u8] {
37 self.borrow_owner()
38 }
39
40 pub fn raw_str(&self) -> Option<&str> {
41 std::str::from_utf8(self.borrow_owner()).ok()
42 }
43
44 pub fn request_id(&self) -> Option<&RequestId> {
45 match self.borrow_dependent() {
46 Response::Done { ref tag, .. } => Some(tag),
47 _ => None,
48 }
49 }
50
51 pub fn parsed(&self) -> &Response<'_> {
52 self.borrow_dependent()
53 }
54}