This tilde
crate utilizes the disused tilde operator ~
to generate
syntatic sugar for Rust program.
first_arg.~the_macro!(rest_args)
, which will
be desugared as the_macro!( first_arg, rest_args )
. As proposed in
simple postfix macros #2442,
first_arg
will be evaluated excactly once.rust
macro_rules! inc { ($e:expr) => { $e+1 }}
Suppose i: i32
, The library user could write: i.~inc!()
,
i.clone().~inc!()
etc, which is a sugar as inc!( i )
and
inc!( i.clone() )
.
This feature is in compliance with RFC 2442:
```rust macrorules! logvalue { ( $self:expr, $msg:expr ) => ({ $self.1.push_str( &format!( "{}:{}: {}: {:?}", file!(), line!(), $msg, $self.0 )); $self }) }
fn value
tilde! { #[test] fn rfcpr2442() { let mut log1 = String::new(); let mut log2 = String::new(); ( value( "hello", &mut log1 ).~logvalue!( "value" ).0.len(), &mut log2 ).~logvalue!( "len" ); let log = format!( "{}\n{}", log1, log2 ); asserteq!( log, r#"evaluated "hello" tildederive/src/lib.rs:72: value: "hello" tilde_derive/src/lib.rs:72: len: 5"# ); } } ```
More features will be added in the future.
Licensed under MIT.