which checks if an std::io::Error is the one we created with a specific string using Error::new(ErrorKind::Other, MY_ERROR). However, this is broken on recent versions of the Rust language because description() now returns:
inner.description() = "description() is deprecated; use Display"
How can I update this comparison to avoid description() without allocating memory?
So the inner error needs to be io::Error, too? I interpreted your code as MY_ERROR being a &'static str, so I thought we could construct the outer io::Error via io::Error::new(io::ErrorKind::Other, MyError(MY_ERROR)), getting to the description of the inner error via io::Error::get_ref.
Here's another possibility for comparing a impl Display with a &str without allocating a String, though if you can skip the formatting machinery it will likely be better:
Thanks but I'm a bit busy right now Just linking to this thread from the PR is fine for me.
That said I think @Schard's approach of using get_ref + downcast_ref is both cleaner and faster, though it requires creating a custom struct for RUNTIME_SHUTTING_DOWN_ERROR instead of using a plain string.
Right now I'm just concerned with working around the breaking change in the stdlib. Using a custom enum requires changes in several places in the codebase, and while that may be a good idea, I don't think it should be part of a bugfix.
I'd disagree. Introducing a complex hack instead of cleaning up the architecture when compensating for an API change would not be acceptable for me. But then, I am not the crate author, you are.
Ok, but the other change is also complex. Is it a breaking change to introduce an enum like this? It could break downstream crates downcasting std::io::Error to string. I think it's probably acceptable, but I don't want to find out with the bugfix, especially not if I backport that fix to LTS, since if I end up needing to revert it, then the revert needs to be backported too.