fourchan-rs 0.1.1

Async 4chan JSON API client and type bindings
Documentation
use serde::Deserialize;

/// `threads.json`, the lightweight summary list of every active thread on a
/// board, useful for cheap polling with `If-Modified-Since`.
#[derive(Debug, Clone, Deserialize)]
#[serde(transparent)]
pub struct ThreadList(pub Vec<ThreadListPage>);

#[derive(Debug, Clone, Deserialize)]
pub struct ThreadListPage {
    pub page: u32,
    pub threads: Vec<ThreadStub>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct ThreadStub {
    pub no: u64,            /// OP number.
    pub last_modified: i64, /// Unix timestamp 
    pub replies: u32,
}

impl ThreadList {
    pub fn pages(&self) -> &[ThreadListPage] { &self.0 }

    pub fn threads(&self) -> impl Iterator<Item = &ThreadStub> {
        self.0.iter().flat_map(|p| p.threads.iter())
    }
}