diff --git a/ruma-api-macros/src/lib.rs b/ruma-api-macros/src/lib.rs index 51797c8b..97c52d07 100644 --- a/ruma-api-macros/src/lib.rs +++ b/ruma-api-macros/src/lib.rs @@ -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 macro is used on. Specifically, if no `#[wrap_incoming]` attribute is used on any of the -/// fields of the struct, this simple implementation will be generated: +/// derive macro is used on. Specifically, if no lifetime variables are used on any of the fields +/// of the struct, this simple implementation will be generated: /// /// ```ignore /// impl Outgoing for MyType { /// type Incoming = Self; /// } /// ``` -/// -/// 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) -/// is generated, with all of the fields with `#[wrap_incoming]` replaced: -/// -/// ```ignore -/// #[derive(Outgoing)] -/// struct MyType { -/// pub foo: Foo, -/// #[wrap_incoming] -/// pub bar: Bar, -/// #[wrap_incoming(Baz)] -/// pub baz: Option, -/// #[wrap_incoming(with EventResult)] -/// pub x: XEvent, -/// #[wrap_incoming(YEvent with EventResult)] -/// pub ys: Vec, -/// } -/// -/// // generated -/// struct IncomingMyType { -/// pub foo: Foo, -/// pub bar: IncomingBar, -/// pub baz: Option, -/// pub x: EventResult, -/// pub ys: Vec>, -/// } -/// ``` -// 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))] + +/* TODO: Extend docs. Previously: + +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) +is generated, with all of the fields with `#[wrap_incoming]` replaced: + +```ignore +#[derive(Outgoing)] +struct MyType { + pub foo: Foo, + #[wrap_incoming] + pub bar: Bar, + #[wrap_incoming(Baz)] + pub baz: Option, + #[wrap_incoming(with EventResult)] + pub x: XEvent, + #[wrap_incoming(YEvent with EventResult)] + pub ys: Vec, +} + +// generated +struct IncomingMyType { + pub foo: Foo, + pub bar: IncomingBar, + pub baz: Option, + pub x: EventResult, + pub ys: Vec>, +} +``` + +*/ +#[proc_macro_derive(Outgoing, attributes(incoming_no_deserialize))] pub fn derive_outgoing(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); expand_derive_outgoing(input).unwrap_or_else(|err| err.to_compile_error()).into()