mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-14 06:12:29 +00:00
Perform type magic for recursive AsRef on Ext types
This commit is contained in:
parent
4ab09044ab
commit
8305cd8116
8 changed files with 32 additions and 52 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "activitystreams"
|
||||
description = "Activity Streams in Rust"
|
||||
version = "0.5.0-alpha.16"
|
||||
version = "0.5.0-alpha.17"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
||||
|
@ -17,7 +17,7 @@ primitives = ["chrono", "mime", "serde", "thiserror", "url"]
|
|||
types = ["derive", "kinds", "primitives"]
|
||||
|
||||
[dependencies]
|
||||
activitystreams-derive = { version = "0.5.0-alpha.8", path = "activitystreams-derive", optional = true}
|
||||
activitystreams-derive = { version = "0.5.0-alpha.9", path = "activitystreams-derive", optional = true}
|
||||
chrono = { version = "0.4", optional = true }
|
||||
mime = { version = "0.3", optional = true }
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
|
|
|
@ -9,7 +9,7 @@ __A set of Traits and Types that make up the ActivityStreams and ActivityPub spe
|
|||
|
||||
First, add ActivityStreams to your dependencies
|
||||
```toml
|
||||
activitystreams = "0.5.0-alpha.16"
|
||||
activitystreams = "0.5.0-alpha.17"
|
||||
```
|
||||
|
||||
### Types
|
||||
|
@ -177,7 +177,7 @@ There are a number of features that can be disabled in this crate. By default, e
|
|||
enabled.
|
||||
|
||||
```toml
|
||||
activitystreams = { version = "0.5.0-alpha.16", default-features = "false", features = ["derive"] }
|
||||
activitystreams = { version = "0.5.0-alpha.17", default-features = "false", features = ["derive"] }
|
||||
```
|
||||
|
||||
| feature | what you get |
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "activitystreams-derive"
|
||||
description = "Derive macros for activitystreams"
|
||||
version = "0.5.0-alpha.8"
|
||||
version = "0.5.0-alpha.9"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix.dev@gmail.com>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
||||
|
|
|
@ -10,7 +10,7 @@ Add the required crates to your `Cargo.toml`
|
|||
```toml
|
||||
# Cargo.toml
|
||||
|
||||
activitystreams = "0.5.0-alpha.16"
|
||||
activitystreams = "0.5.0-alpha.17"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
```
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
//!
|
||||
//! First, add `serde` and `activitystreams-derive` to your Cargo.toml
|
||||
//! ```toml
|
||||
//! activitystreams-derive = "0.5.0-alpha.8"
|
||||
//! # or activitystreams = "0.5.0-alpha.16"
|
||||
//! activitystreams-derive = "0.5.0-alpha.9"
|
||||
//! # or activitystreams = "0.5.0-alpha.17"
|
||||
//! serde = { version = "1.0", features = ["derive"] }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -269,49 +269,11 @@ pub fn ref_derive(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
impl<U> AsRef<#ty> for Ext<#name, U>
|
||||
where
|
||||
U: std::fmt::Debug,
|
||||
{
|
||||
fn as_ref(&self) -> &#ty {
|
||||
self.base.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<U, V> AsRef<#ty> for Ext<Ext<#name, U>, V>
|
||||
where
|
||||
U: std::fmt::Debug,
|
||||
V: std::fmt::Debug,
|
||||
{
|
||||
fn as_ref(&self) -> &#ty {
|
||||
self.base.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<#ty> for #name {
|
||||
fn as_mut(&mut self) -> &mut #ty {
|
||||
&mut self.#ident
|
||||
}
|
||||
}
|
||||
|
||||
impl<U> AsMut<#ty> for Ext<#name, U>
|
||||
where
|
||||
U: std::fmt::Debug,
|
||||
{
|
||||
fn as_mut(&mut self) -> &mut #ty {
|
||||
self.base.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<U, V> AsMut<#ty> for Ext<Ext<#name, U>, V>
|
||||
where
|
||||
U: std::fmt::Debug,
|
||||
V: std::fmt::Debug,
|
||||
{
|
||||
fn as_mut(&mut self) -> &mut #ty {
|
||||
self.base.as_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
25
src/ext.rs
25
src/ext.rs
|
@ -126,10 +126,9 @@ use std::{convert::TryFrom, fmt::Debug};
|
|||
/// For example, the type `Ext<Video, HashMap<String, String>>` will implement the `Object` trait,
|
||||
/// because `Video` implements that trait.
|
||||
///
|
||||
/// Additionally, some level of AsRef and AsMut have been derived for Ext. If type type
|
||||
/// Additionally, AsRef and AsMut have been implemented for Ext. If type type
|
||||
/// `Ext<Ext<Follow, SomeTime>, AnotherType>` exists, that will implement
|
||||
/// `AsRef<ActivityProperties>` just like the innermost `Follow`. This only works for types
|
||||
/// two levels deep, however.
|
||||
/// `AsRef<ActivityProperties>` just like the innermost `Follow`.
|
||||
///
|
||||
/// Usage:
|
||||
/// ```rust
|
||||
|
@ -204,6 +203,26 @@ pub trait Extensible<U> {
|
|||
Self: Sized;
|
||||
}
|
||||
|
||||
impl<T, U, V> AsRef<V> for Ext<T, U>
|
||||
where
|
||||
T: Base + AsRef<V>,
|
||||
U: Extension<T> + Debug,
|
||||
{
|
||||
fn as_ref(&self) -> &V {
|
||||
self.base.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U, V> AsMut<V> for Ext<T, U>
|
||||
where
|
||||
T: Base + AsMut<V>,
|
||||
U: Extension<T> + Debug,
|
||||
{
|
||||
fn as_mut(&mut self) -> &mut V {
|
||||
self.base.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> TryFrom<Ext<T, U>> for BaseBox
|
||||
where
|
||||
T: Base + serde::ser::Serialize,
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
//!
|
||||
//! First, add ActivityStreams to your dependencies
|
||||
//! ```toml
|
||||
//! activitystreams = "0.5.0-alpha.16"
|
||||
//! activitystreams = "0.5.0-alpha.17"
|
||||
//! ```
|
||||
//!
|
||||
//! ### Types
|
||||
|
@ -209,7 +209,7 @@
|
|||
//! enabled.
|
||||
//!
|
||||
//! ```toml
|
||||
//! activitystreams = { version = "0.5.0-alpha.16", default-features = "false", features = ["derive"] }
|
||||
//! activitystreams = { version = "0.5.0-alpha.17", default-features = "false", features = ["derive"] }
|
||||
//! ```
|
||||
//!
|
||||
//! | feature | what you get |
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
use crate::{
|
||||
ext::Ext,
|
||||
link::{kind::*, properties::*, Link, LinkBox},
|
||||
Base, BaseBox, PropRefs,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue