let sp = SpinnerBuilder::new("Long Running op!".into()).
format(|sp, status|{
format!("{spin} -- Currently working on: \'{status}\' -- {spin}",
spin = sp, status = status)
}).start();
I can understand none of it . What are names inside brackets? Rust has no string comprehension. What are format!("...", spin = sp, status = status) arguments, and what is = in this context?. I sort of guess why there are three pairs of braces, and only two arguments, yet can't actually understand it.
They are named placeholders which will be formatted. They correspond to the left-hand side of the assignment-looking parameters inside the format!(…) invocation.
That's just how the syntax of the format!() macro is defined. It accepts key-value pairs, so the key = value syntax is used to specify what values should be inserted wherever the corresponding placeholder occurs in the format string.
There are three uses of two arguments. You can use a single argument (named or not) more than once in a format string.
let sp = SpinnerBuilder::new("Long Running op!".into())
.format(|spin, status| format!("{spin} -- Currently working on: \'{status}\' -- {spin}"))
.start();
Does this mean rust has string comprehension as of tomorrow? Maybe not, it's just macro processing, but close enough for me.