3 ms·
The most useful function is Arguments::fmt. “as_str” is just a shortcut utility function.
by orf 2y ago
The most useful function is Arguments::fmt. “as_str” is just a shortcut utility function.
- lifthrasiir 2y agoIt is not a shortcut because it can't be implemented without knowing the `Arguments` internals. `format_args!("{}", "boo").as_str()` returns None for example.
- orf 2y agoIt’s a shortcut in the sense that most, if not all optimisations are shortcuts. This one allows you to shortcut the usual formatting machinery if the result of formatting is a static string. Like all shortcuts, it’s not something you can always rely on.
- lifthrasiir 2y agoIt can be used to shortcut the formatting process, the function itself is however not a shortcut in my opinion.
- orf 2y agoInteresting viewpoint: I see this as a distinction without a difference. I’m interested to know why you see it differently? What is its use, if not as a shortcut?
- tialaramex 2y agoBut there is no Arguments::fmt ? Are you thinking of the implementations of Debug::fmt and Display::fmt on Arguments ? Trait implementation isn't the same kind of thing at all.
- orf 2y agoThere is exactly one useful thing you can do with an `Arguments` object: call `.fmt()` on it. The whole reason for std::Arguments very existence is to call `std::Arguments::fmt` on it. `.fmt()` is a trait implementation, but that doesn’t change anything (not sure what “kind of thing” refers to here). It’s still a function on std::Arguments.
- tialaramex 2y agoI think you're quite muddled about what's going on here The full name of this type is std::fmt::Arguments not std::Arguments and even so there's no such thing as std::fmt::Arguments::fmt - there is no function with that name, we can only talk about this name (since it doesn't exist) if we bring into context a specific trait such as Display or Debug So the full name of the thing you think is the "one useful thing you can do with Arguments" is <std::fmt::Arguments as std::fmt::Display>::fmt or perhaps it's <std::fmt::Arguments as std::fmt::Debug>::fmt ... as I said, Arguments implements both traits, and their sole function has the same name so we need to disambiguate somehow if we mean one of these functions or the other. For the function defined on Arguments itself, as_str, it's already unambiguous. In the end the Debug and Display traits are all just ductwork, which is why as_str caught my attention.