diff --git a/libafl_derive/src/lib.rs b/libafl_derive/src/lib.rs index 361405bf401..a803ebd3977 100644 --- a/libafl_derive/src/lib.rs +++ b/libafl_derive/src/lib.rs @@ -77,16 +77,44 @@ pub fn libafl_serdeany_derive(input: TokenStream) -> TokenStream { /// Options: Some => inner type display None => "". /// Vec: inner type display space separated concatenation. /// Generics and other more or less exotic stuff are not supported. +/// +/// # Examples +/// +/// ```rust +/// use libafl_derive; +/// +/// #[derive(libafl_derive::Display)] +/// struct MyStruct { +/// foo: String, +/// bar: Option, +/// } +/// ``` +/// +/// The above code will expand to: +/// +/// ```rust +/// struct MyStruct { +/// foo: String, +/// bar: Option, +/// } +/// +/// impl core::fmt::Display for MyStruct { +/// fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { +/// f.write_fmt(format_args!(" {0}", self.foo))?; +/// if let Some(opt) = &self.bar { +/// f.write_fmt(format_args!(" {0}", opt))?; +/// } +/// Ok(()) +/// } +/// } +/// ``` #[proc_macro_derive(Display)] pub fn libafl_display(input: TokenStream) -> TokenStream { let DeriveInput { ident, data, .. } = parse_macro_input!(input as DeriveInput); if let Struct(s) = data { if let Named(fields) = s.fields { - let fields_fmt = fields - .named - .iter() - .map(libafl_display_field_by_type); + let fields_fmt = fields.named.iter().map(libafl_display_field_by_type); return quote! { impl core::fmt::Display for #ident {