From 7b7b755f477c71fd4fd4f7e6f3049216b8ebc5eb Mon Sep 17 00:00:00 2001 From: Joe Doyle Date: Tue, 25 Nov 2025 17:04:13 -0500 Subject: [PATCH] Convert get_mark() to MARK associated constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Updated trait definition to use const MARK - Modified derive macro to generate constants instead of methods - Updated documentation to reflect the new API - Adapted test to use constant reference for custom marks Resolves #6 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- inscribe-derive/src/lib.rs | 14 +++++--------- src/inscribe.rs | 6 +++--- tests/inscribe_tests.rs | 8 +------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/inscribe-derive/src/lib.rs b/inscribe-derive/src/lib.rs index b499ccb..2314cda 100644 --- a/inscribe-derive/src/lib.rs +++ b/inscribe-derive/src/lib.rs @@ -175,7 +175,7 @@ fn implement_get_inscription(dstruct: &DataStruct) -> TokenStream { use decree::decree::FSInput; let mut serial_out: Vec = Vec::new(); - let mut hasher = TupleHash::v256(self.get_mark().as_bytes()); + let mut hasher = TupleHash::v256(Self::MARK.as_bytes()); // Add the struct members into the TupleHash #center @@ -196,12 +196,10 @@ fn implement_default_mark(ast: &DeriveInput) -> TokenStream { let ident = &ast.ident; let ident_str = ident.to_string(); - let get_mark = quote!{ - fn get_mark(&self) -> &'static str { - return #ident_str; - } + let mark = quote!{ + const MARK: &'static str = #ident_str; }; - get_mark + mark } fn implement_get_addl(ast: &DeriveInput) -> TokenStream { @@ -255,9 +253,7 @@ fn implement_get_mark(ast: &DeriveInput) -> TokenStream { if let Some(meta) = nested.iter().next() { match meta { Meta::Path(path) => { mark_implementation = quote!{ - fn get_mark(&self) -> &'static str { - self.#path() - } + const MARK: &'static str = #path; }}, _ => { panic!("Invalid metadata for field attribute"); }, } diff --git a/src/inscribe.rs b/src/inscribe.rs index cf9728d..858a0cb 100644 --- a/src/inscribe.rs +++ b/src/inscribe.rs @@ -8,14 +8,14 @@ pub type InscribeBuffer = [u8; INSCRIBE_LENGTH]; /// contextual data into Fiat-Shamir transcripts. There are two main methods that the trait /// requires: /// -/// `fn get_mark(&self) -> &'static str` +/// `const MARK: &'static str` /// /// and /// /// `fn get_inscription(&self) -> FSInput` /// /// For derived structs, the `get_inscription` method will do the following: -/// - Initialize a TupleHash with the results of `get_mark` +/// - Initialize a TupleHash with the contents of `MARK` /// - For each member of the struct, do one of three things: /// + For `Inscribe` implementers, call `get_inscription` and add the results to the /// TupleHash @@ -124,7 +124,7 @@ pub type InscribeBuffer = [u8; INSCRIBE_LENGTH]; /// ``` /// pub trait Inscribe { - fn get_mark(&self) -> &'static str; + const MARK: &'static str; fn get_inscription(&self) -> DecreeResult; fn get_additional(&self) -> DecreeResult { let x: Vec = Vec::new(); diff --git a/tests/inscribe_tests.rs b/tests/inscribe_tests.rs index cc75bb9..33395e2 100644 --- a/tests/inscribe_tests.rs +++ b/tests/inscribe_tests.rs @@ -12,7 +12,7 @@ mod tests { const MARK_TEST_DATA: &str = "Atypical mark!"; #[derive(Inscribe)] - #[inscribe_mark(atypical_mark)] + #[inscribe_mark(MARK_TEST_DATA)] struct Point { #[inscribe(serialize)] #[inscribe_name(input_2)] @@ -22,12 +22,6 @@ mod tests { y: i32, } - impl Point { - fn atypical_mark(&self) -> &'static str { - MARK_TEST_DATA - } - } - #[derive(Inscribe)] #[inscribe_addl(additional_data_method)] struct InscribeTest {