I found this excellent blog post about error handling in Rust.
It defines an error struct as such:
struct ProgramError {
kind: ProgramErrorKind,
message: SendStr
}
For the message it uses SendStr
which is an type alias for MaybeOwned<'static>
. I understand that this can either hold an &str
or an String
but the documentation is a bit vague about its use case.
This can be useful as an optimization when an allocation is sometimes needed but not always.
I would like to understand why one would like to choose SendStr
over &str
or String
in the case of defining a ProgramError
class.