/** * High level stream API for ZotApi. * * The stream API will parse the raw json response from a stream (network * or channel stream) into proper types, that should be easier to use from * a client application. * * SPDX-FileCopyrightText: 2023 Eilertsens Kodeknekkeri * SPDX-FileCopyrightText: 2023 Harald Eilertsen * * SPDX-License-Identifier: AGPL-3.0-or-later */ mod activity; mod actor; mod datetime; mod tag; mod verb; pub use actor::Actor; pub use datetime::DateTime; pub use activity::{ Activity, ActivityEncoding, ActivityType, }; pub use tag::{ Tag, TagType, }; pub use verb::Verb; use std::{ error::Error, result::Result }; #[derive(Debug, PartialEq)] pub struct Stream { pub items: Vec, } impl Stream { pub fn from_json(json: &str) -> Result> { let items: Vec = serde_json::from_str(&json)?; Ok(Self { items }) } } #[cfg(test)] mod test { use super::*; #[test] fn construct_stream_from_empty_string_should_fail() { let s = Stream::from_json(""); assert!(s.is_err()); } #[test] fn construct_stream_from_empty_json() { let s = Stream::from_json("[]"); assert!(s.is_ok()); } }