async_pop/response/
uidl.rs1use super::types::{message::Text, number::Number};
2
3#[derive(Debug)]
4pub enum UidlResponse {
5 Multiple(Uidl),
6 Single(UniqueId),
7}
8
9impl From<Uidl> for UidlResponse {
10 fn from(value: Uidl) -> Self {
11 Self::Multiple(value)
12 }
13}
14
15impl From<UniqueId> for UidlResponse {
16 fn from(value: UniqueId) -> Self {
17 Self::Single(value)
18 }
19}
20
21#[derive(Debug)]
22pub struct Uidl {
23 message: Option<Text>,
24 items: Vec<UniqueId>,
25}
26
27impl Uidl {
28 pub fn new<M: Into<Text>>(message: Option<M>, items: Vec<UniqueId>) -> Self {
29 Self {
30 message: message.map(|msg| msg.into()),
31 items,
32 }
33 }
34
35 pub fn items(&self) -> &[UniqueId] {
36 self.items.as_ref()
37 }
38
39 pub fn message(&self) -> Option<&Text> {
40 self.message.as_ref()
41 }
42}
43
44#[derive(Debug)]
45pub struct UniqueId {
46 index: Number,
47 id: Text,
48}
49
50impl UniqueId {
51 pub fn new<I: Into<Number>, D: Into<Text>>(index: I, id: D) -> Self {
52 Self {
53 index: index.into(),
54 id: id.into(),
55 }
56 }
57
58 pub fn index(&self) -> &Number {
59 &self.index
60 }
61
62 pub fn id(&self) -> &Text {
63 &self.id
64 }
65}