Incorporate feedback by lu-fennell, Nauxuron
This commit is contained in:
parent
7d340942a0
commit
9fa1305e65
@ -75,6 +75,7 @@ impl Request {
|
|||||||
pub fn has_header_fields(&self) -> bool {
|
pub fn has_header_fields(&self) -> bool {
|
||||||
self.fields.iter().any(|field| field.is_header())
|
self.fields.iter().any(|field| field.is_header())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether or not this request has any data in the URL path.
|
/// Whether or not this request has any data in the URL path.
|
||||||
pub fn has_path_fields(&self) -> bool {
|
pub fn has_path_fields(&self) -> bool {
|
||||||
self.fields.iter().any(|field| field.is_path())
|
self.fields.iter().any(|field| field.is_path())
|
||||||
|
@ -32,7 +32,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
Data::Struct(s) => match s.fields {
|
Data::Struct(s) => match s.fields {
|
||||||
Fields::Named(fs) => fs.named.into_pairs().map(Pair::into_value).collect(),
|
Fields::Named(fs) => fs.named.into_pairs().map(Pair::into_value).collect(),
|
||||||
Fields::Unnamed(fs) => fs.unnamed.into_pairs().map(Pair::into_value).collect(),
|
Fields::Unnamed(fs) => fs.unnamed.into_pairs().map(Pair::into_value).collect(),
|
||||||
Fields::Unit => return Ok(impl_send_recv_incoming_self(input.ident)),
|
Fields::Unit => return Ok(impl_outgoing_with_incoming_self(input.ident)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ pub fn expand_derive_outgoing(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !any_attribute {
|
if !any_attribute {
|
||||||
return Ok(impl_send_recv_incoming_self(input.ident));
|
return Ok(impl_outgoing_with_incoming_self(input.ident));
|
||||||
}
|
}
|
||||||
|
|
||||||
let vis = input.vis;
|
let vis = input.vis;
|
||||||
@ -104,7 +104,7 @@ fn no_deserialize_in_attrs(attrs: &[Attribute]) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impl_send_recv_incoming_self(ident: Ident) -> TokenStream {
|
fn impl_outgoing_with_incoming_self(ident: Ident) -> TokenStream {
|
||||||
quote! {
|
quote! {
|
||||||
impl ruma_api::Outgoing for #ident {
|
impl ruma_api::Outgoing for #ident {
|
||||||
type Incoming = Self;
|
type Incoming = Self;
|
||||||
|
@ -73,8 +73,10 @@ pub fn ruma_api(input: TokenStream) -> TokenStream {
|
|||||||
/// pub ys: Vec<EventResult<YEvent>>,
|
/// 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(wrap_incoming, incoming_no_deserialize))]
|
||||||
pub fn derive_send_recv(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()
|
||||||
}
|
}
|
||||||
|
@ -200,11 +200,12 @@ use serde_urlencoded;
|
|||||||
///
|
///
|
||||||
/// ## Fallible deserialization
|
/// ## Fallible deserialization
|
||||||
///
|
///
|
||||||
/// All request and response types also derive `ruma_api::Outgoing`. As such, to allow fallible
|
/// All request and response types also derive [`Outgoing`][]. As such, to allow fallible
|
||||||
/// deserialization, you can use the `#[wrap_incoming]` attribute. For details, see the
|
/// deserialization, you can use the `#[wrap_incoming]` attribute. For details, see the
|
||||||
/// documentation for [`Outgoing`][].
|
/// documentation for [`Outgoing`][].
|
||||||
///
|
///
|
||||||
/// [`Outgoing`]: derive.Outgoing.html
|
/// [`Outgoing`]: derive.Outgoing.html
|
||||||
|
// TODO: Explain the concept of fallible deserialization before jumping to `ruma_api::Outgoing`
|
||||||
#[cfg(feature = "with-ruma-api-macros")]
|
#[cfg(feature = "with-ruma-api-macros")]
|
||||||
pub use ruma_api_macros::ruma_api;
|
pub use ruma_api_macros::ruma_api;
|
||||||
|
|
||||||
@ -230,6 +231,7 @@ pub mod exports {
|
|||||||
/// ruma_events' `EventResult` type. For more details, see the [derive macro's documentation][doc].
|
/// ruma_events' `EventResult` type. For more details, see the [derive macro's documentation][doc].
|
||||||
///
|
///
|
||||||
/// [doc]: derive.Outgoing.html
|
/// [doc]: derive.Outgoing.html
|
||||||
|
// TODO: Better explain how this trait relates to serde's traits
|
||||||
pub trait Outgoing {
|
pub trait Outgoing {
|
||||||
/// The 'Incoming' variant of `Self`.
|
/// The 'Incoming' variant of `Self`.
|
||||||
type Incoming;
|
type Incoming;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user