tafkars 0.1.0

The API formerly known as...
Documentation
use serde::{Deserialize, Serialize};
/// JSON list response.
#[derive(Serialize, Deserialize, Debug)]
pub struct ListingData<T> {
    /// Modhash
    pub modhash: Option<String>,
    /// The number of children in the listing.
    pub dist: Option<i32>,
    /// The fullname of the listing that follows after this page.
    pub after: Option<String>,
    /// The fullname of the listing that follows before this page.
    pub before: Option<String>,
    /// A list of `things` that this Listing wraps.
    pub children: Vec<T>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "kind", rename = "Listing")]
pub struct Listing<T> {
    pub data: ListingData<T>,
}

impl<T> Listing<T> {
    pub fn new(items: Vec<T>) -> Self {
        Self {
            data: ListingData {
                modhash: None,
                dist: None,
                after: None,
                before: None,
                children: items,
            },
        }
    }
    pub fn push(&mut self, item: T) {
        self.data.children.push(item);
    }
}