-
Notifications
You must be signed in to change notification settings - Fork 46
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
Seprate HeaderSliceWithLength into checked and unchecked variants #108
Conversation
9903ea3
to
1b65f34
Compare
r? @steffahn if you have time |
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.
src/thin_arc.rs
Outdated
pub fn with_arc<F, U>(&self, f: F) -> U | ||
where | ||
F: FnOnce(&Arc<HeaderSliceWithLength<H, [T]>>) -> U, | ||
F: FnOnce(&Arc<HeaderSliceWithLengthChecked<H, [T]>>) -> U, | ||
{ |
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.
Probably only with_arc_mut
should change, this is breaking old API.
src/thin_arc.rs
Outdated
/// Converts a `ThinArc` into an `Arc`. This consumes the `ThinArc`, so the refcount | ||
/// is not modified. | ||
#[inline] | ||
pub fn checked_header_from_thin(a: ThinArc<H, T>) -> Self { |
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’m not really happy with the naming, haven’t thought of better alternatives yet.
The problem is that now there’s Arc::from_thin
and Arc::checked_header_from_thin
, and the latter just sounds more heavy, like there’s additional checking going on, even though the exact opposite is the case (you get something that needs less checking in order to convert back).
Actually, now I have an idea: how about the word becomes “protected”?
E.g. HeaderSliceWithLengthProtected
instead of HeaderSliceWithLengthChecked
. (And the HeaderSliceWithLengthUnchecked
type synonym isn’t needed at all.)
Then we can have Arc::from_thin
and Arc::protected_from_thin
. That sounds less like additional “checking” is going on.
And we can have ThinArc::with_arc
and ThinArc::with_protected_arc
(the latter can also serve to be used internally an implementation that replaces the unsafe check-less clone
from #76). We could even consider to keep with_arc_mut
[with sufficient checks, i.e. under documented threat of abort] and add with_protected_arc_mut
next to it, making the naming more consistent.
Or (coming back to naming) another idea is HeaderSliceWithConstLen
, and thus Arc::const_len_from_thin
, ThinArc::with_const_len_arc
and ThinArc::with_const_len_arc_mut
.
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'm not happy with the naming either, this is just the naming that's stable. The unchecked variant should be more verbose.
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.
Protected seems fine for now. I don't like the implication of const
here with the const naming.
Okay, finally starting another round of review. I’m wondering if |
I wonder if Other types kind-of have no rules… except Ultimately, |
@Manishearth I've tried this out myself, so you don't have to; see #110 ;-) |
Other than the suggestions above, this PR looks good to me. |
Merging this first, I'll get around to your changes soon. The reason I didn't want to make HeaderSliceWithLengthProtected contain a slice directly was that I was worried about the |
Fixes #107
The breakage is limited to
with_mut()
, which now returns aHeaderSliceWithLengthChecked
which has an immutable header.Not fully happy with the resultant API, worth cleaning up in the next major release.