From e1a688efb16f96a6dca3678c67ff38b7cabfa8c6 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 7 Jul 2026 15:10:21 -0700 Subject: More augments and setup for use from other crates. --- crimtag/Cargo.toml | 1 + crimtag/src/context.rs | 6 ++++++ crimtag/src/lib.rs | 2 ++ derive/src/lib.rs | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crimtag/Cargo.toml b/crimtag/Cargo.toml index ee022ca..e48d065 100644 --- a/crimtag/Cargo.toml +++ b/crimtag/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] +derive = {path="../derive"} diff --git a/crimtag/src/context.rs b/crimtag/src/context.rs index 15448ee..a922fd8 100644 --- a/crimtag/src/context.rs +++ b/crimtag/src/context.rs @@ -148,6 +148,12 @@ basic_mapped_value_from!(f32, Float32); basic_mapped_value_from!(f64, Float64); basic_mapped_value_from!(bool, Bool); +impl<'a> MappedStructure<'a> for HashMap { + fn get_value(&'a self, id: &str) -> Option> { + self.get(id).map(|x|MappedValue::String(x)) + } +} + impl<'a> From<&'a String> for MappedValue<'a> { fn from(val: &'a String ) -> MappedValue<'a> { MappedValue::String(val) diff --git a/crimtag/src/lib.rs b/crimtag/src/lib.rs index e8f9e9f..0fe0e4e 100644 --- a/crimtag/src/lib.rs +++ b/crimtag/src/lib.rs @@ -9,6 +9,8 @@ mod position; mod error; pub mod context; +pub use derive::CrimtagMappable; + pub use error::{CrimError,CrimResult}; pub use position::*; pub use context::{Context,Value,MappedStructure,StatefulContext,MappedValue,MappedList,MappedHash}; diff --git a/derive/src/lib.rs b/derive/src/lib.rs index bb299d0..379ebe7 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -1,5 +1,5 @@ extern crate proc_macro; -use proc_macro::{TokenStream,TokenTree,Ident,Delimiter}; +use proc_macro::{TokenStream,TokenTree,/*Ident,*/Delimiter}; use lookahead::LookAhead; @@ -24,7 +24,7 @@ pub fn derive_crimtag_mappable(s: TokenStream) -> TokenStream { let mut newfunc = format!( r#"impl<'a> crimtag::MappedStructure<'a> for {} {{ - fn get_value(&'a self, id: &str) -> Option> {{ + fn get_value(&'a self, id: &str) -> Option> {{ match id {{ "#, name); -- cgit v1.2.3