diff --git a/acrate_astreams/Cargo.toml b/acrate_astreams/Cargo.toml index 6aed621..029b290 100644 --- a/acrate_astreams/Cargo.toml +++ b/acrate_astreams/Cargo.toml @@ -20,6 +20,7 @@ static-iref = "3.0.0" thiserror = "2.0.3" mediatype = { version = "0.19.18", features = ["serde"] } language-tags = { version = "0.3.2", features = ["serde"] } +chrono = { version = "0.4.39", features = ["serde"] } [dev-dependencies] tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread"] } diff --git a/acrate_astreams/src/activitystreams/mod.rs b/acrate_astreams/src/activitystreams/mod.rs index bb0d37c..444f85c 100644 --- a/acrate_astreams/src/activitystreams/mod.rs +++ b/acrate_astreams/src/activitystreams/mod.rs @@ -12,24 +12,52 @@ //! use anyhow::Result as AResult; +use chrono::{DateTime, Local, TimeDelta, Timelike}; use json_ld::Direction; use json_ld::syntax::LangTagBuf; use mediatype::MediaType; pub mod jsonld; +// TODO: What to do with the LangTriple? Whose responsibility is it? + /// Something that is either a [`StreamsObject`] or a [`StreamsLink`]. pub trait StreamsEntity<Preview> where Preview: StreamsEntity<Preview>, { + fn activitystreams_names(&self) -> impl Iterator<Item = AResult<(String, Option<LangTagBuf>, Option<Direction>)>>; fn activitystreams_previews(&self) -> impl Iterator<Item = AResult<Preview>>; + fn activitystreams_mediatype(&self) -> Option<AResult<MediaType>>; } /// Something that can be considered a `https://www.w3.org/ns/activitystreams#Object`. -pub trait StreamsObject<Preview> where +pub trait StreamsObject<Preview, Attachment, Attribution, Audience, Context, Tag, Link, Target> where Self: StreamsEntity<Preview>, + Preview: StreamsEntity<Preview>, + Attachment: StreamsEntity<Preview>, + Audience: StreamsEntity<Preview>, + Context: StreamsEntity<Preview>, + Tag: StreamsEntity<Preview>, + Link: StreamsLink<Preview>, + Target: StreamsEntity<Preview>, { - + fn activitystreams_attachments(&self) -> impl Iterator<Item = AResult<Attachment>>; + fn activitystreams_attributedto(&self) -> impl Iterator<Item = AResult<Attribution>>; + fn activitystreams_audiences(&self) -> impl Iterator<Item = AResult<Audience>>; + fn activitystreams_content(&self) -> impl Iterator<Item = AResult<(String, Option<LangTagBuf>, Option<Direction>)>>; + fn activitystreams_context(&self) -> impl Iterator<Item = AResult<Context>>; + fn activitystreams_endtime(&self) -> Option<AResult<DateTime<Local>>>; + fn activitystreams_published(&self) -> Option<AResult<DateTime<Local>>>; + fn activitystreams_starttime(&self) -> Option<AResult<DateTime<Local>>>; + fn activitystreams_summaries(&self) -> impl Iterator<Item = AResult<(String, Option<LangTagBuf>, Option<Direction>)>>; + fn activitystreams_tags(&self) -> impl Iterator<Item = AResult<Audience>>; + fn activitystreams_updated(&self) -> Option<AResult<DateTime<Local>>>; + fn activitystreams_urls(&self) -> impl Iterator<Item = AResult<Link>>; + fn activitystreams_to(&self) -> impl Iterator<Item = AResult<Target>>; + fn activitystreams_bto(&self) -> impl Iterator<Item = AResult<Target>>; + fn activitystreams_cc(&self) -> impl Iterator<Item = AResult<Target>>; + fn activitystreams_bcc(&self) -> impl Iterator<Item = AResult<Target>>; + fn activitystreams_duration(&self) -> Option<AResult<TimeDelta>>; } /// Something that can be considered a `https://www.w3.org/ns/activitystreams#Link`. @@ -42,10 +70,6 @@ pub trait StreamsLink<Preview> where // FIXME: This accepts any kind of string, and does not filter to HTML link relations fn activitystreams_rels_lenient(&self) -> impl Iterator<Item = AResult<String>>; - fn activitystreams_mediatype(&self) -> Option<AResult<MediaType>>; - - fn activitystreams_names(&self) -> impl Iterator<Item = AResult<(String, Option<LangTagBuf>, Option<Direction>)>>; - fn activitystreams_hreflang(&self) -> Option<AResult<LangTagBuf>>; // FIXME: This doesn't accept numbers greater than u64