Optionally typetag, update docs

This commit is contained in:
Aode 2020-03-09 13:04:11 -05:00
parent 62c8d245ff
commit 2c0658d77e
2 changed files with 21 additions and 4 deletions

View file

@ -142,14 +142,22 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
let name = name.clone(); let name = name.clone();
let ext_trait = Ident::new(&format!("{}Ext", object), name.span()); let ext_trait = Ident::new(&format!("{}Ext", object), name.span());
let activity_impls = quote! { let tt = if object.to_string() == "Object" || object.to_string() == "Link" {
quote! {
#[typetag::serde] #[typetag::serde]
}
} else {
quote! {}
};
let activity_impls = quote! {
#tt
impl #object for #name { impl #object for #name {
fn as_any(&self) -> &std::any::Any { fn as_any(&self) -> &dyn std::any::Any {
self self
} }
fn as_any_mut(&self) -> &mut std::any::Any { fn as_any_mut(&self) -> &mut dyn std::any::Any {
self self
} }
} }

View file

@ -25,6 +25,7 @@
//! use activitystreams_traits::Object; //! use activitystreams_traits::Object;
//! use activitystreams_types::object::properties::ObjectProperties; //! use activitystreams_types::object::properties::ObjectProperties;
//! use serde_derive::{Deserialize, Serialize}; //! use serde_derive::{Deserialize, Serialize};
//! use std::any::Any;
//! //!
//! #[derive(Clone, Debug, Serialize, Deserialize)] //! #[derive(Clone, Debug, Serialize, Deserialize)]
//! #[serde(rename_all = "camelCase")] //! #[serde(rename_all = "camelCase")]
@ -39,7 +40,15 @@
//! pub object_properties: ObjectProperties, //! pub object_properties: ObjectProperties,
//! } //! }
//! //!
//! impl Object for MyObject {} //! impl Object for MyObject {
//! fn as_any(&self) -> &dyn Any {
//! self
//! }
//!
//! fn as_any_mut(&mut self) -> &mut dyn Any {
//! self
//! }
//! }
//! # //! #
//! # fn main() {} //! # fn main() {}
//! ``` //! ```