So, imagine having a len! macro. Literally just that.
Well, there aren't a lot of reasons...
Use-case #1:
let world = "World";
let helloworld = String::with_capacity(len!("Hello "), world.len());
println!("{}", helloworld);
Use-case #2:
let string = "prefix!!yay";
if string.starts_with("prefix!!") {
let string = &string[len!("prefix!!")..];
assert_eq!(string, "yay");
}
Both of those examples could use .len().
Except "prefix!!".len() isn't retrieved at compile time.
@legolord208 What difference does it make? It still optimizes to a constant, always.
Oh :thinking:.... Ooops, didn't realize
Most helpful comment
Except
"prefix!!".len()isn't retrieved at compile time.