Crate activitystreams_derive [] [src]

Derive macros for Activity Streams


extern crate activitystreams_derive;
extern crate activitystreams_traits;
extern crate serde;
extern crate serde_derive;
extern crate serde_json;

use activitystreams_traits::{Link, Object};

/// Using the UnitString derive macro
/// This macro implements Serialize and Deserialize for the given type, making this type
/// represent the string "SomeKind" in JSON.
#[derive(Clone, Debug, Default, UnitString)]
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)]
#[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>,

    /// Use the UnitString MyKind to enforce the type of the object by "SomeKind"
    #[serde(rename = "type")]
    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
    /// 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,