-
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
Implement RefCell::{try_borrow, try_borrow_mut}
#35425
Conversation
The error structs may want to implement some additional traits, but those can be added later. |
#[derive(Clone, Debug)] | ||
#[unstable(feature = "try_borrow", issue = "35070")] | ||
pub struct BorrowError { | ||
_inner: (), |
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.
What _inner
field for?
You can write just
pub struct BorrowError {
}
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.
This way it can't be constructed outside the module
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.
Yeah, I copied this from the RFC itself, and it can always be removed before being stabilized.
Thanks @apasel422! To be maximally conservative as well, could you add a lifetime parameter to the two error types so it's connected to struct Error<'a, T> {
inner: marker::PhantomData<&'a RefCell<T>>,
} Also, could you be sure to add |
@alexcrichton Sure. Do you still want a |
Nah it should be fine to omit for now I think |
Updated. |
not be exposed publicly", | ||
issue = "0")] | ||
#[doc(hidden)] | ||
pub fn __description(&self) -> &str { |
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.
Despite this being how std::num
does it in a few locations, that's just because the variants in core aren't available in std. For something like these errors it should be fine to just put this error string directly into std, no need to worry about reducing the duplication of this string literal!
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.
Done.
Implement `RefCell::{try_borrow, try_borrow_mut}` CC #35070 r? @alexcrichton
CC #35070
r? @alexcrichton