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"
[dependencies]
activitystreams-traits = { version = "0.3", path = "activitystreams-traits" }
activitystreams-types = { version = "0.3.0", path = "activitystreams-types" }
activitystreams-traits = { version = "0.3.0", path = "activitystreams-traits" }
activitystreams-types = { version = "0.4.0", path = "activitystreams-types" }
[dev-dependencies]
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
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]
opt-level = 3

View file

@ -3,25 +3,27 @@ __derive macros for ActivityStreams__
- [Read the documentation on docs.rs](https://docs.rs/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
Add the required crates to your `Cargo.toml`
```toml
# Cargo.toml
activitystreams-derive = "0.2"
activitystreams-traits = "0.2"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
activitystreams-derive = "0.3"
activitystreams-traits = "0.3"
activitystreams-types = "0.4"
serde = { version = "1.0", features = ["derive"] }
```
And then in your project
```rust
use activitystreams_derive::{Properties, UnitString};
use activitystreams_traits::{Link, Object};
use serde_derive::{Deserialize, Serialize};
use activitystreams_derive::{properties, PropRefs, UnitString};
use activitystreams_traits::Object;
use activitystreams_types::object::{
properties::ObjectProperties,
ObjectExt,
};
/// Using the UnitString derive macro
///
@ -31,27 +33,72 @@ use serde_derive::{Deserialize, Serialize};
#[activitystreams(SomeKind)]
pub struct MyKind;
/// Using the Properties derive macro
///
/// This macro generates getters and setters for the associated fields.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
properties! {
My {
docs [
"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")]
pub struct MyProperties {
/// Derive getters and setters for @context with Link and Object traits.
#[serde(rename = "@context")]
#[activitystreams(ab(Object, Link))]
pub context: Option<serde_json::Value>,
pub struct My {
/// Derive AsRef<MyProperties> and AsMut<MyProperties>
#[serde(flatten)]
#[activitystreams(None)]
my_properties: MyProperties,
/// Use the UnitString MyKind to enforce the type of the object by "SomeKind"
pub kind: MyKind,
/// Derive getters and setters for required_key with String type.
/// Derive AsRef<ObjectProperties> and AsMut<ObjectProperties>
///
/// 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>.
#[activitystreams(concrete(String), functional)]
pub required_key: serde_json::Value,
/// as well as the Object and ObjectExt traits
#[serde(flatten)]
#[activitystreams(Object)]
properties: ObjectProperties,
}
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
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.

View file

@ -1,7 +1,7 @@
/*
* 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
* 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)
- [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
projects. See the `activitystreams-types` crate for examples of how these traits could be used.
## 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
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")]
pub struct Persona {
#[serde(rename = "type")]
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 {}
```
@ -30,7 +51,7 @@ Feel free to open issues for anything you find an issue with. Please note that a
## 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.

View file

@ -1,7 +1,7 @@
/*
* 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
* 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.
*
* 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

View file

@ -1,7 +1,7 @@
/*
* 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
* 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.
*
* 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
@ -39,8 +39,19 @@
//! }
//!
//! #[typetag::serde]
//! impl Object for Persona {}
//! #[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 {}
//!
//! # fn main() {}

View file

@ -1,7 +1,7 @@
/*
* 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
* 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.
*
* 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
@ -26,9 +26,18 @@ use std::any::Any;
/// `Collection` and `OrderedCollection`.
#[typetag::serde(tag = "type")]
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;
/// 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;
/// 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>;
}

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams-types"
description = "Base types from the Activity Streams spec"
version = "0.3.0"
version = "0.4.0"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
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)
- [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
First, add the crate to your cargo.toml
First, add the crate to your `Cargo.toml`
```toml
# Cargo.toml
activitystreams-types = "0.3"
activitystreams-types = "0.4"
```
Then use it in your project!
@ -18,12 +18,11 @@ Then use it in your project!
// in your project
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
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)?;
@ -38,7 +37,7 @@ Feel free to open issues for anything you find an issue with. Please note that a
## 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.

View file

@ -1,7 +1,7 @@
/*
* 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
* 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.
*
* 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

View file

@ -1,7 +1,7 @@
/*
* 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
* 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.
*
* 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

View file

@ -1,7 +1,7 @@
/*
* 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
* 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.
*
* 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

View file

@ -1,7 +1,7 @@
/*
* 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
* it under the terms of the GNU General Public License as published by