From 9556c3e843a3e35bc4363528ccbac98b389dfce1 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Fri, 3 Nov 2023 11:44:40 +0000 Subject: [PATCH] Document `with` attr --- udigest/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/udigest/src/lib.rs b/udigest/src/lib.rs index 11aba25..9a6b46b 100644 --- a/udigest/src/lib.rs +++ b/udigest/src/lib.rs @@ -150,6 +150,32 @@ pub use encoding::Buffer; /// data: Data /// } /// ``` +/// * `#[udigest(with = ...)]` \ +/// Can be used to override the field encoding. Accepts as input a function with a signature: +/// ```rust,no_run +/// # type T = String; +/// fn encoder(value: &T, encoder: udigest::encoding::EncodeValue) +/// where +/// B: udigest::Buffer +/// # {} +/// ``` +/// Example: +/// ```rust +/// #[derive(udigest::Digestable)] +/// pub struct User { +/// name: String, +/// // `Instant` encoding is not provided by `udigest` crate, but it +/// // can be manually provided +/// #[udigest(with = encode_instant)] +/// created_at: std::time::Instant, +/// } +/// fn encode_instant( +/// instant: &std::time::Instant, +/// encoder: udigest::encoding::EncodeValue +/// ) { +/// todo!() +/// } +/// ``` /// * `#[udigest(rename = "...")]` \ /// Specifies another name to use for the field. As field name gets mixed into the hash, /// changing the field name will change the hash. Sometimes, it may be required to change