std::error::Error
trait defines fn description(&self) -> &str
method, which is not very useful.
- It can’t (easily) allocate a formatted string, so in practice it’s just used to return a static string vaguely describing the error without any specific per-instance information.
-
fmt::Display
is much more useful for errors and it can provide precise description even without allocating.
So currently we have a situation where every implementor of Error
spends time creating a method that has minimal utility and generally shouldn’t be used. New users lose a battle with the borrow checker here trying to return format!()
. A second description has to be written in Display
. That’s a waste of everyone’s time.
I suggest:
-
Documenting that use of this method is discouraged. Not formally deprecated in form of shouty
#[deprecated]
attr, just steer user away from it. -
Provide default implementation in the stdlib, so that this method effectively becomes optional and users can pretend it doesn’t exist if they want to.
The default implementation could returnstd::intrinsics::type_name::<Self>()
, which would preserve some minimal utility, but I wouldn’t mind returning anything else like"unspecified error"
or"
"