Skip to content

Commit

Permalink
add non-breaking macro
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Nov 18, 2017
1 parent 51f7a49 commit 9d45683
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ macro_rules! gtmpl_fn {
Ok(Arc::new(Value::from(inner()?)))
}
};
(
$(#[$outer:meta])*
fn $name:ident($arg0:ident : $typ0:ty) -> Result<$otyp:ty, String>
{ $($body:tt)* }
) => {
$(#[$outer])*
pub fn $name(args: &[::std::sync::Arc<::std::any::Any>]) -> Result<::std::sync::Arc<::std::any::Any>, String> {
if args.is_empty() {
return Err(String::from("at least one argument required"));
}
let x = &args[0];
let $arg0 = x.downcast_ref::<::gtmpl_value::Value>()
.ok_or_else(|| "unable to downcast".to_owned())?;
let $arg0: $typ0 = ::gtmpl_value::from_value($arg0)
.ok_or_else(|| "unable to convert from Value".to_owned())?;
fn inner($arg0 : $typ0) -> Result<$otyp, String> {
$($body)*
}
let ret: ::gtmpl_value::Value = inner($arg0)?.into();
Ok(::std::sync::Arc::new(ret))
}
};
(
$(#[$outer:meta])*
fn $name:ident($arg0:ident : $typ0:ty$(, $arg:ident : $typ:ty),*) -> Result<$otyp:ty, String>
Expand Down

0 comments on commit 9d45683

Please sign in to comment.