Start updating Readmes, dates

This commit is contained in:
asonix 2020-03-10 11:48:54 -05:00
parent 4bbb6ad206
commit ae02f234a0
19 changed files with 147 additions and 60 deletions

View file

@ -10,14 +10,14 @@ keywords = ["activitystreams", "activitypub"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
activitystreams-traits = { version = "0.3", path = "activitystreams-traits" } activitystreams-traits = { version = "0.3.0", path = "activitystreams-traits" }
activitystreams-types = { version = "0.3.0", path = "activitystreams-types" } activitystreams-types = { version = "0.4.0", path = "activitystreams-types" }
[dev-dependencies] [dev-dependencies]
anyhow = "1.0" anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
activitystreams-derive = { version = "0.3", path = "activitystreams-derive" } activitystreams-derive = { version = "0.3.0", path = "activitystreams-derive" }
[profile.dev.package.activitystreams-derive] [profile.dev.package.activitystreams-derive]
opt-level = 3 opt-level = 3

View file

@ -3,25 +3,27 @@ __derive macros for ActivityStreams__
- [Read the documentation on docs.rs](https://docs.rs/activitystreams-derive) - [Read the documentation on docs.rs](https://docs.rs/activitystreams-derive)
- [Find the crate on crates.io](https://crates.io/crates/activitystreams-derive) - [Find the crate on crates.io](https://crates.io/crates/activitystreams-derive)
- [Join the discussion on Matrix](https://matrix.to/#/!fAEcHyTUdAaKCzIKCt:asonix.dog?via=asonix.dog) - [Hit me up on Mastodon](https://asonix.dog/@asonix)
## Usage ## Usage
Add the required crates to your `Cargo.toml` Add the required crates to your `Cargo.toml`
```toml ```toml
# Cargo.toml # Cargo.toml
activitystreams-derive = "0.2" activitystreams-derive = "0.3"
activitystreams-traits = "0.2" activitystreams-traits = "0.3"
serde = "1.0" activitystreams-types = "0.4"
serde_derive = "1.0" serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
``` ```
And then in your project And then in your project
```rust ```rust
use activitystreams_derive::{Properties, UnitString}; use activitystreams_derive::{properties, PropRefs, UnitString};
use activitystreams_traits::{Link, Object}; use activitystreams_traits::Object;
use serde_derive::{Deserialize, Serialize}; use activitystreams_types::object::{
properties::ObjectProperties,
ObjectExt,
};
/// Using the UnitString derive macro /// Using the UnitString derive macro
/// ///
@ -31,27 +33,72 @@ use serde_derive::{Deserialize, Serialize};
#[activitystreams(SomeKind)] #[activitystreams(SomeKind)]
pub struct MyKind; pub struct MyKind;
/// Using the Properties derive macro properties! {
/// My {
/// This macro generates getters and setters for the associated fields. docs [
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] "Using the properties macro",
"",
"This macro generates getters and setters for the associated fields.",
],
kind {
docs [
"Use the UnitString MyKind to enforce the type of the object by \"SomeKind\"",
"",
"Rename to/from 'type' when serializing/deserializing",
],
types [
MyKind,
],
functional,
required,
rename("type"),
},
required_key {
docs [
"Derive getters and setters for required_key with String type.",
"",
"In the Activity Streams spec, 'functional' means there can only be one item for",
"this key. This means all fields not labeled 'functional' can also be",
"serialized/deserialized as Vec<T>.",
"",
"'required' here means that the field must be present, otherwise, it's"
"represented as an Option<T>",
],
types [
String,
],
functional,
required,
},
}
}
#[derive(Clone, Default, PropRefs, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct MyProperties { pub struct My {
/// Derive getters and setters for @context with Link and Object traits. /// Derive AsRef<MyProperties> and AsMut<MyProperties>
#[serde(rename = "@context")] #[serde(flatten)]
#[activitystreams(ab(Object, Link))] #[activitystreams(None)]
pub context: Option<serde_json::Value>, my_properties: MyProperties,
/// Use the UnitString MyKind to enforce the type of the object by "SomeKind" /// Derive AsRef<ObjectProperties> and AsMut<ObjectProperties>
pub kind: MyKind,
/// Derive getters and setters for required_key with String type.
/// ///
/// In the Activity Streams spec, 'functional' means there can only be one item for this /// as well as the Object and ObjectExt traits
/// key. This means all fields not labeled 'functional' can also be serialized/deserialized #[serde(flatten)]
/// as Vec<T>. #[activitystreams(Object)]
#[activitystreams(concrete(String), functional)] properties: ObjectProperties,
pub required_key: serde_json::Value, }
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut my = My::default();
my.as_mut().set_required_key("Hello")?;
assert_eq!(my.as_ref().get_required_key(), "Hello");
Ok(())
} }
``` ```
@ -60,7 +107,7 @@ Feel free to open issues for anything you find an issue with. Please note that a
## License ## License
Copyright © 2018 Riley Trautman Copyright © 2020 Riley Trautman
ActivityStreams Derive is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ActivityStreams Derive is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Derive. * This file is part of ActivityStreams Derive.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Derive is free software: you can redistribute it and/or modify * ActivityStreams Derive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -3,25 +3,46 @@ __Traits for Activity Streams__
- [Read the documentation on docs.rs](https://docs.rs/activitystreams-traits) - [Read the documentation on docs.rs](https://docs.rs/activitystreams-traits)
- [Find the crate on crates.io](https://crates.io/crates/activitystreams-traits) - [Find the crate on crates.io](https://crates.io/crates/activitystreams-traits)
- [Join the discussion on Matrix](https://matrix.to/#/!fAEcHyTUdAaKCzIKCt:asonix.dog?via=asonix.dog) - [Hit me up on Mastodon](https://asonix.dog/@asonix)
These traits don't provide any functionality other than anotations for types created in other These traits don't provide any functionality other than anotations for types created in other
projects. See the `activitystreams-types` crate for examples of how these traits could be used. projects. See the `activitystreams-types` crate for examples of how these traits could be used.
## Examples ## Examples
Add it to your `Cargo.toml`
```toml
activitystreams-traits = "0.3"
serde = { version = "1.0", features = ["derive"] }
typetag = "0.1.4"
```
Use it in your project
```rust ```rust
use activitystreams_traits::{Object, Actor}; use activitystreams_traits::{Object, Actor};
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Persona { pub struct Persona {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: String, kind: String,
} }
impl Object for Persona {} // TypeTag exists so user-defined types can be deserialized generically in activitystreams-types
#[typetag::serde]
impl Object for Persona {
fn as_any(&self) -> &(dyn Any + 'static) {
self
}
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static) {
self
}
fn duplicate(&self) -> Box<dyn Object + 'static> {
Box::new(self.clone())
}
}
impl Actor for Persona {} impl Actor for Persona {}
``` ```
@ -30,7 +51,7 @@ Feel free to open issues for anything you find an issue with. Please note that a
## License ## License
Copyright © 2018 Riley Trautman Copyright © 2020 Riley Trautman
ActivityStreams Traits is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ActivityStreams Traits is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Traits. * This file is part of ActivityStreams Traits.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Traits is free software: you can redistribute it and/or modify * ActivityStreams Traits is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Traits. * This file is part of ActivityStreams Traits.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Traits is free software: you can redistribute it and/or modify * ActivityStreams Traits is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Traits. * This file is part of ActivityStreams Traits.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Traits is free software: you can redistribute it and/or modify * ActivityStreams Traits is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Traits. * This file is part of ActivityStreams Traits.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Traits is free software: you can redistribute it and/or modify * ActivityStreams Traits is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -39,8 +39,19 @@
//! } //! }
//! //!
//! #[typetag::serde] //! #[typetag::serde]
//! impl Object for Persona {} //! impl Object for Persona {
//! #[typetag::serde] //! fn as_any(&self) -> &(dyn Any + 'static) {
//! self
//! }
//!
//! fn as_any_mut(&mut self) -> &mut (dyn Any + 'static) {
//! self
//! }
//!
//! fn duplicate(&self) -> Box<dyn Object + 'static> {
//! Box::new(self.clone())
//! }
//! }
//! impl Actor for Persona {} //! impl Actor for Persona {}
//! //!
//! # fn main() {} //! # fn main() {}

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Traits. * This file is part of ActivityStreams Traits.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Traits is free software: you can redistribute it and/or modify * ActivityStreams Traits is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Traits. * This file is part of ActivityStreams Traits.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Traits is free software: you can redistribute it and/or modify * ActivityStreams Traits is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,9 +26,18 @@ use std::any::Any;
/// `Collection` and `OrderedCollection`. /// `Collection` and `OrderedCollection`.
#[typetag::serde(tag = "type")] #[typetag::serde(tag = "type")]
pub trait Object: std::fmt::Debug { pub trait Object: std::fmt::Debug {
/// Provide an as_any method to allow for borrowed downcasting.
///
/// This is useful since Objects can be deserialized generically via typetag
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
/// Provide an as_any method to allow for mutably borrowed downcasting.
///
/// This is useful since Objects can be deserialized generically via typetag
fn as_any_mut(&mut self) -> &mut dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any;
/// Provide a duplicate method to allow for cloning type objects.
///
/// This is useful since Objects can be deserialized generically via typetag
fn duplicate(&self) -> Box<dyn Object>; fn duplicate(&self) -> Box<dyn Object>;
} }

View file

@ -1,7 +1,7 @@
[package] [package]
name = "activitystreams-types" name = "activitystreams-types"
description = "Base types from the Activity Streams spec" description = "Base types from the Activity Streams spec"
version = "0.3.0" version = "0.4.0"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams" repository = "https://git.asonix.dog/Aardwolf/activitystreams"

View file

@ -3,14 +3,14 @@ __A base set of types from the Activity Streams specification.__
- [Read the documentation on docs.rs](https://docs.rs/activitystreams-types) - [Read the documentation on docs.rs](https://docs.rs/activitystreams-types)
- [Find the crate on crates.io](https://crates.io/crates/activitystreams-types) - [Find the crate on crates.io](https://crates.io/crates/activitystreams-types)
- [Join the discussion on Matrix](https://matrix.to/#/!fAEcHyTUdAaKCzIKCt:asonix.dog?via=asonix.dog) - [Hit me up on Mastodon](https://asonix.dog/@asonix)
## Usage ## Usage
First, add the crate to your cargo.toml First, add the crate to your `Cargo.toml`
```toml ```toml
# Cargo.toml # Cargo.toml
activitystreams-types = "0.3" activitystreams-types = "0.4"
``` ```
Then use it in your project! Then use it in your project!
@ -18,12 +18,11 @@ Then use it in your project!
// in your project // in your project
use activitystreams_types::{context, link::Mention}; use activitystreams_types::{context, link::Mention};
use failure::Error;
fn run() -> Result<(), Error> { fn run() -> Result<(), Box<dyn std::error::Error>> {
/// A Mention is the only predefined Link type in the Activity Streams spec /// A Mention is the only predefined Link type in the Activity Streams spec
let mut mention = Mention::default(); let mut mention = Mention::default();
mention.link_props.set_context_object(context())?; mention.as_ref().set_context_xsd_any_uri(context())?;
let mention_string = serde_json::to_string(&mention)?; let mention_string = serde_json::to_string(&mention)?;
@ -38,7 +37,7 @@ Feel free to open issues for anything you find an issue with. Please note that a
## License ## License
Copyright © 2018 Riley Trautman Copyright © 2020 Riley Trautman
ActivityStreams Types is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ActivityStreams Types is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of ActivityStreams Types. * This file is part of ActivityStreams Types.
* *
* Copyright © 2018 Riley Trautman * Copyright © 2020 Riley Trautman
* *
* ActivityStreams Types is free software: you can redistribute it and/or modify * ActivityStreams Types is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by