From 5330b9b7fea45347e87687ab0b55522e272c664d Mon Sep 17 00:00:00 2001 From: bbaldino Date: Wed, 21 May 2025 16:07:56 -0700 Subject: [PATCH 1/2] docs: update 'map' readme example --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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, } - ```
From 08c3c6101f60103bb9707769dde9b99b9dca4d4d Mon Sep 17 00:00:00 2001 From: bbaldino Date: Thu, 22 May 2025 16:09:46 -0700 Subject: [PATCH 2/2] remove some commented-out debug prints --- impl/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) 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)) }