Fix outdated docs on Outgoing derive

This commit is contained in:
Jonas Platte 2020-08-17 21:17:09 +02:00
parent e06c800701
commit 4a52931af7
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -36,45 +36,47 @@ pub fn ruma_api(input: TokenStream) -> TokenStream {
} }
/// Derive the `Outgoing` trait, possibly generating an 'Incoming' version of the struct this /// Derive the `Outgoing` trait, possibly generating an 'Incoming' version of the struct this
/// derive macro is used on. Specifically, if no `#[wrap_incoming]` attribute is used on any of the /// derive macro is used on. Specifically, if no lifetime variables are used on any of the fields
/// fields of the struct, this simple implementation will be generated: /// of the struct, this simple implementation will be generated:
/// ///
/// ```ignore /// ```ignore
/// impl Outgoing for MyType { /// impl Outgoing for MyType {
/// type Incoming = Self; /// type Incoming = Self;
/// } /// }
/// ``` /// ```
///
/// If, however, `#[wrap_incoming]` is used (which is the only reason you should ever use this /* TODO: Extend docs. Previously:
/// derive macro manually), a new struct `IncomingT` (where `T` is the type this derive is used on)
/// is generated, with all of the fields with `#[wrap_incoming]` replaced: If, however, `#[wrap_incoming]` is used (which is the only reason you should ever use this
/// derive macro manually), a new struct `IncomingT` (where `T` is the type this derive is used on)
/// ```ignore is generated, with all of the fields with `#[wrap_incoming]` replaced:
/// #[derive(Outgoing)]
/// struct MyType { ```ignore
/// pub foo: Foo, #[derive(Outgoing)]
/// #[wrap_incoming] struct MyType {
/// pub bar: Bar, pub foo: Foo,
/// #[wrap_incoming(Baz)] #[wrap_incoming]
/// pub baz: Option<Baz>, pub bar: Bar,
/// #[wrap_incoming(with EventResult)] #[wrap_incoming(Baz)]
/// pub x: XEvent, pub baz: Option<Baz>,
/// #[wrap_incoming(YEvent with EventResult)] #[wrap_incoming(with EventResult)]
/// pub ys: Vec<YEvent>, pub x: XEvent,
/// } #[wrap_incoming(YEvent with EventResult)]
/// pub ys: Vec<YEvent>,
/// // generated }
/// struct IncomingMyType {
/// pub foo: Foo, // generated
/// pub bar: IncomingBar, struct IncomingMyType {
/// pub baz: Option<IncomingBaz>, pub foo: Foo,
/// pub x: EventResult<XEvent>, pub bar: IncomingBar,
/// pub ys: Vec<EventResult<YEvent>>, pub baz: Option<IncomingBaz>,
/// } pub x: EventResult<XEvent>,
/// ``` pub ys: Vec<EventResult<YEvent>>,
// TODO: Make it clear that `#[wrap_incoming]` and `#[wrap_incoming(Type)]` without the "with" part }
// are (only) useful for fallible deserialization of nested structures. ```
#[proc_macro_derive(Outgoing, attributes(wrap_incoming, incoming_no_deserialize))]
*/
#[proc_macro_derive(Outgoing, attributes(incoming_no_deserialize))]
pub fn derive_outgoing(input: TokenStream) -> TokenStream { pub fn derive_outgoing(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput); let input = parse_macro_input!(input as DeriveInput);
expand_derive_outgoing(input).unwrap_or_else(|err| err.to_compile_error()).into() expand_derive_outgoing(input).unwrap_or_else(|err| err.to_compile_error()).into()