pub struct StrMapFunc { /* private fields */ }Expand description
Generates a lookup function for all the key-value pairs contained in the tree.
§Examples
use enum_utils_from_str::StrMapFunc;
// Compiling this trie into a lookup function...
let mut code = vec![];
StrMapFunc::new("custom_lookup", "bool")
.entries(vec![
("yes", true),
("yep", true),
("no", false),
])
.compile(&mut code);
// results in the following generated code.
fn custom_lookup(s: &[u8]) -> Option<bool> {
match s.len() {
2 => if s[0] == b'n' && s[1] == b'o' {
return Some(false);
},
3 => if s[0] == b'y' && s[1] == b'e' {
if s[2] == b'p' {
return Some(true);
} else if s[2] == b's' {
return Some(true);
}
},
_ => {}
}
None
}
Implementations§
Source§impl StrMapFunc
impl StrMapFunc
pub fn new(func_name: &str, ret_ty: &str) -> Self
pub fn case(&mut self, case: Case) -> &mut Self
pub fn entry(&mut self, k: &str, v: impl ToTokens) -> &mut Self
pub fn entries<'a, V>(
&mut self,
entries: impl IntoIterator<Item = (&'a str, V)>,
) -> &mut Selfwhere
V: ToTokens + 'a,
pub fn compile(&self, w: impl Write) -> Result<()>
Trait Implementations§
Source§impl Clone for StrMapFunc
impl Clone for StrMapFunc
Source§fn clone(&self) -> StrMapFunc
fn clone(&self) -> StrMapFunc
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ToTokens for StrMapFunc
impl ToTokens for StrMapFunc
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Auto Trait Implementations§
impl !Send for StrMapFunc
impl !Sync for StrMapFunc
impl Freeze for StrMapFunc
impl RefUnwindSafe for StrMapFunc
impl Unpin for StrMapFunc
impl UnsafeUnpin for StrMapFunc
impl UnwindSafe for StrMapFunc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more