-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[stdlib] Add Error.as_string_slice()
and polish
#4304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
), | ||
")", | ||
) | ||
return String("Error(", repr(self.as_string_slice()), ")") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the repr
necessary (can we make it "Error('"
etc.)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't like building a String unnecessarily, but I don't know whether to remove this. It adds "
to the end and beginning of the message or '
if the message contains "
, it also encodes control characters in the ASCII range. Since it encodes those characters instead of printing, I think it's worth it in cases where you would want to print something that might have been corrupted on the way. But I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Maybe we should make repr
return a different Writable
than String
in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe once we have some API for streaming a repr i.e. __repr__(self, mut writer: Writer)
Signed-off-by: martinvuyk <[email protected]>
Signed-off-by: martinvuyk <[email protected]>
Signed-off-by: martinvuyk <[email protected]>
92a9cad
to
b97aded
Compare
Add
Error.as_string_slice()
and polish