diff --git a/README.md b/README.md index b3b69b5..9237b13 100644 --- a/README.md +++ b/README.md @@ -177,17 +177,20 @@ returns a `ParselyResult` where U is `ParselyWrite`.
Click to expand -This (quite contrived) example has a boolean field but reads a u1 from the +This example has a String field but reads a u8 from the buffer and converts it. On write it does the opposite. ```rust +use parsely_rs::*; + #[derive(ParselyRead, ParselyWrite)] struct Foo { - #[parsely_read(map = "|v: u1| -> ParselyResult { Ok(v > 0) }")] - #[parsely_write(map = "|v: &bool| -> ParselyResult { Ok(u1::from(*v)) }")] - one: bool, + // Closures can return a raw value... + #[parsely_read(map = "|v: u8| { v.to_string() }")] + // ...or a Result as long as E: Into + #[parsely_write(map = "|v: &str| { v.parse::() }")] + value: String, } - ```
diff --git a/impl/src/lib.rs b/impl/src/lib.rs index 9670f45..79f9188 100644 --- a/impl/src/lib.rs +++ b/impl/src/lib.rs @@ -36,8 +36,6 @@ use syn_helpers::TypeExts; pub fn derive_parsely_read(item: TokenStream) -> std::result::Result { let ast: DeriveInput = syn::parse2(item)?; let data = ParselyReadData::from_derive_input(&ast)?; - // eprintln!("parsely_read data = {data:#?}"); - // eprintln!("HELLO, WORLD, item = {ast:#?}"); Ok(generate_parsely_read_impl(data)) } @@ -46,8 +44,6 @@ pub fn derive_parsely_read(item: TokenStream) -> std::result::Result std::result::Result { let ast: DeriveInput = syn::parse2(item)?; let data = ParselyWriteData::from_derive_input(&ast)?; - // eprintln!("parsely_write data = {data:#?}"); - // eprintln!("HELLO, WORLD, item = {ast:#?}"); Ok(generate_parsely_write_impl(data)) }