Conversation
|
Getting the return type of this right is an interesting rabbit hole! My initial thinking was We can't return a If we change the signature to something like: two questions arise:
I think the answer to both of these questions is yes. We can achieve the first by defining a pub struct ReadBuffer<'a, Dst>(Pin<&'a mut MaybeUninit<Dst>>);
impl<'a, Dst> ReadBuffer<'a, Dst> {
pub fn from_maybe_uninit(src: Pin<&'a mut MaybeUninit<Dst>>) -> Self {
use zerocopy::FromZeros;
ReadBuffer(unsafe {
src.map_unchecked_mut(|src| { src.zero(); src })
})
}
}...and we can achieve the second by using our EDIT: Actually, I think this is unsound under reverse transmutation. |
|
I'm still working on exploring the problem space, presently by considering what a fn try_mut_from_io<R>(mut source: R, buffer: &mut CoreMaybeUninit<Self>) -> io::Result<Result<&mut Self, ValidityError<&[u8], Self>>>
where
Self: KnownLayout + Sized,
R: io::Read,Note the lack of an |
d6013bb to
f54136d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2619 +/- ##
==========================================
- Coverage 88.72% 88.40% -0.33%
==========================================
Files 20 20
Lines 5332 5356 +24
==========================================
+ Hits 4731 4735 +4
- Misses 601 621 +20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/lib.rs
Outdated
| // TODO: Write tests for this method | ||
| #[cfg(feature = "std")] | ||
| #[inline(always)] | ||
| fn try_read_from_io<R>(mut src: R) -> io::Result<Result<Self, ValidityError<[u8; 0], Self>>> |
There was a problem hiding this comment.
Why not just ValidityError<(), Self>? [u8; 0] seems a bit unnecessary. I feel like () conveys "we're not providing a source value."
There was a problem hiding this comment.
We'll want it to be something that's Deref so if it's embedded in a ConvertError, the whole package implements Error. So how about &'static ().
There was a problem hiding this comment.
Eh, between &'static () and [u8; 0], I'd prefer [u8; 0].
There was a problem hiding this comment.
It would need to be &'static [u8; 0]
There was a problem hiding this comment.
Which I think is worse, tbh.
There was a problem hiding this comment.
Oh I see. Yeah, agreed that &'static () is better.
f54136d to
af48300
Compare
Makes progress on #158 gherrit-pr-id: Ia15467145b06dd57e4dfd9e127fdd6d7a313ecba
af48300 to
97ce7a8
Compare
Makes progress on #158
gherrit-pr-id: Ia15467145b06dd57e4dfd9e127fdd6d7a313ecba