1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::prelude::*;
#[non_exhaustive]
#[derive(Debug)]
pub struct Poll {
pub by: String,
pub comments: u64,
pub id: u64,
pub(crate) kids: Vec<u64>,
pub(crate) parts: Vec<u64>,
pub score: i64,
pub text: String,
pub time: u64,
pub title: String,
}
impl Poll {
pub fn by(&self, client: &Client) -> Result<User, HError> {
client.get_user(&self.by)
}
pub fn comments(&self, client: &Client) -> Result<Vec<Comment>, HError> {
self.kids
.iter()
.map(|kid| client.get_comment(*kid))
.collect()
}
pub fn options(&self, client: &Client) -> Result<Vec<PollOption>, HError> {
self.parts
.iter()
.map(|kid| client.get_poll_option(*kid))
.collect()
}
}
#[non_exhaustive]
#[derive(Debug)]
pub struct PollOption {
pub by: String,
pub id: u64,
pub poll: u64,
pub score: i64,
pub text: String,
pub time: u64,
}
impl PollOption {
pub fn by(&self, client: &Client) -> Result<User, HError> {
client.get_user(&self.by)
}
pub fn poll(&self, client: &Client) -> Result<Poll, HError> {
client.get_poll(self.poll)
}
}