-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Show impl for RefCell #14883
Show impl for RefCell #14883
Conversation
I don't think it's appropriate to have |
I think Also this impl doesn't fail, the test makes sure it doesn't. If you mean it might print out something different depending on the state of What it displays when the refcell is already borrowed can easily be changed. I was thinking either show nothing or some kind of message saying it's already borrowed, and the latter is less confusing so I went with that |
Ok yes, this isn't failure in the sense of task failure. but it is failure in the sense that it's unexpectedly showing useless information. |
The other option would be something like this: match self.try_borrow() {
Some(_) => (*self.borrow()).fmt(f),
None => Err(WriteError)
} |
Well, this is why I think it's better to let the client figure out how to handle dynamic borrow failures. Which means let them write |
Incidentally it would be nice if there were another implementation of |
@alexcrichton What do you think? |
I agree, |
The |
Also, I agree that users may want to override it to suit their needs, but there should be some default implementation. Otherwise the only way to print out a complex datastructure with |
@forticulous The error result from Which is to say, using Show to write to an in-memory buffer should never fail. |
If the |
Safe
Show
impl forRefCell
.I'm open to debate about how to handle the case where
try_borrow()
fails. I went with displaying that the refcell is borrowed to minimize surprises