pub struct Thread {
pub posts: Vec<Post>,
}Expand description
A full thread, as returned by /{board}/thread/{no}.json.
Fields§
§posts: Vec<Post>Implementations§
Source§impl Thread
impl Thread
Sourcepub fn op(&self) -> &Post
pub fn op(&self) -> &Post
The OP post, thread.posts[0], present by construction.
Examples found in repository?
examples/poll_thread.rs (line 42)
15async fn main() -> chan::Result<()> {
16 let mut args = env::args().skip(1);
17 let board = args.next().unwrap_or_else(|| "po".to_string());
18 let thread_no: u64 = args
19 .next()
20 .and_then(|s| s.parse().ok())
21 .expect("usage: poll_thread <board> <thread_no>");
22
23 let client = Client::new();
24 let mut seen: HashSet<u64> = HashSet::new();
25 let mut since: Option<String> = None;
26
27 loop {
28 match client
29 .get_full_thread_if_modified(&board, thread_no, since.as_deref())
30 .await
31 {
32 Ok(None) => {
33 eprintln!("304 Not Modified");
34 }
35 Ok(Some(cond)) => {
36 since = cond.last_modified;
37 for post in &cond.value.posts {
38 if seen.insert(post.no) {
39 print_post(&board, post);
40 }
41 }
42 if cond.value.op().archived || cond.value.op().closed {
43 eprintln!("Thread archived or closed. Exiting.");
44 return Ok(());
45 }
46 }
47 Err(chan::Error::NotFound(_)) => {
48 eprintln!("Thread 404'd. Exiting.");
49 return Ok(());
50 }
51 Err(e) => return Err(e),
52 }
53 tokio::time::sleep(Duration::from_secs(30)).await;
54 }
55}Sourcepub fn is_archived(&self) -> bool
pub fn is_archived(&self) -> bool
Whether the thread is archived. Archived threads keep their JSON but their attachments are purged from the CDN, so image URL’s 404.
Sourcepub fn attachments(&self) -> impl Iterator<Item = &Attachment>
pub fn attachments(&self) -> impl Iterator<Item = &Attachment>
Every attachment in the thread, OP first, in post order.
Sourcepub fn image_attachments(&self) -> impl Iterator<Item = &Attachment>
pub fn image_attachments(&self) -> impl Iterator<Item = &Attachment>
Attachments whose extension is a still image. See Attachment::is_image.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Thread
impl<'de> Deserialize<'de> for Thread
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Thread
impl RefUnwindSafe for Thread
impl Send for Thread
impl Sync for Thread
impl Unpin for Thread
impl UnsafeUnpin for Thread
impl UnwindSafe for Thread
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more