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 {