Skip to main content

Thread

Struct Thread 

Source
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

Source

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}
Source

pub fn replies(&self) -> &[Post]

All non-OP posts.

Source

pub fn no(&self) -> u64

OP number. Convenience for op().no.

Source

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.

Source

pub fn attachments(&self) -> impl Iterator<Item = &Attachment>

Every attachment in the thread, OP first, in post order.

Source

pub fn image_attachments(&self) -> impl Iterator<Item = &Attachment>

Attachments whose extension is a still image. See Attachment::is_image.

Trait Implementations§

Source§

impl Clone for Thread

Source§

fn clone(&self) -> Thread

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Thread

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Thread

Source§

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more