Thanks to visit codestin.com
Credit goes to docs.rs

Skip to main content

stringlet

Macro stringlet 

Source
macro_rules! stringlet {
    (_:  $($rest:tt)+) => { ... };
    (var  $($rest:tt)+) => { ... };
    (v  $($rest:tt)+) => { ... };
    (trim  $($rest:tt)+) => { ... };
    (t  $($rest:tt)+) => { ... };
    (slim $($rest:tt)+) => { ... };
    (s  $($rest:tt)+) => { ... };
    ($size:tt:  $($rest:tt)+) => { ... };
    ($($rest:tt)+) => { ... };
}
Expand description

Turn a str expression into the smallest Stringlet that can contain it. Or turn [str, …] into an array of the smallest Stringlet that can contain them. You can explicitly ask for other kinds of stringlet. By default SIZE is the length of the 1st str parameter, in which case that parameter must be const. You can also give the size explicitly, or have it inferred from context along with the kind.

The optional configuration is kind and/or size, if present followed by a colon:

Long Spec |Short Spec |Type
Stringlet<param.len()>
SIZE:Stringlet<SIZE>
var:v:VarStringlet<param.len()>
var SIZE:v SIZE:VarStringlet<SIZE>
trim:t:TrimStringlet<param.len()>
trim SIZE:t SIZE:TrimStringlet<SIZE>
slim:s:SlimStringlet<param.len()>
slim SIZE:s SIZE:SlimStringlet<SIZE>
_:StringletBase<_, _>

These are equivalent:

let s1 = stringlet!("abc");
let s2: Stringlet<3> = stringlet!(_: "abc");
const S3: Stringlet<3> = stringlet!(3: " abc ".trim_ascii());
assert_eq!(s1, s2);
assert_eq!(s2, S3);

As are these:

let s1 = stringlet!(var: ["abcdefghijklmno", "xyz"]);
let s2: [VarStringlet<15>; 2] = stringlet!(_: [&String::from("abcdefghijklmno"), "xyz"]);
const S3: [VarStringlet<15>; 2] = stringlet!(v 15: [concat!("abcdefgh", 'i', "jklmno"), "xyz"]);
assert_eq!(s1, s2);
assert_eq!(s2, S3);