]> git.proxmox.com Git - pxar.git/commitdiff
make the ReadAtImpl enum variants private
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 17 May 2021 12:04:52 +0000 (14:04 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 17 May 2021 12:09:19 +0000 (14:09 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cargo.toml
src/accessor/read_at.rs

index f586e5de5809e74e0a17be41159edbc9e423630a..7e732803fb56f4967101bfcc8a4c55e5f3886606 100644 (file)
@@ -1,5 +1,6 @@
 [package]
 name = "pxar"
+# API broken, next is 0.11.0 (due to `ReadAtImpl` enum variants being made private)
 version = "0.10.1"
 authors = ["Wolfgang Bumiller <w.bumiller@proxmox.com>"]
 edition = "2018"
index d49d08072abbac26aa0273d0d2229bd529ffe224..3c82f702fbc20bdaa57c68c623bc88c483c086f1 100644 (file)
@@ -47,45 +47,65 @@ pub trait ReadAtExt: ReadAt {
     where
         Self: Sized,
     {
-        ReadAtImpl::New(self, buf, offset)
+        ReadAtImpl::new(self, buf, offset)
     }
 }
 
 impl<T: ReadAt> ReadAtExt for T {}
 
-pub enum ReadAtImpl<'a, T: ReadAt> {
+/// Future returned by [`ReadAtExt::read_at`](ReadAtExt::read_at()).
+#[repr(transparent)]
+pub struct ReadAtImpl<'a, T: ReadAt> {
+    state: ReadAtState<'a, T>,
+}
+
+impl<'a, T: ReadAt> ReadAtImpl<'a, T> {
+    fn new(read: &'a T, buf: &'a mut [u8], offset: u64) -> Self {
+        Self {
+            state: ReadAtState::New(read, buf, offset),
+        }
+    }
+}
+
+impl<'a, T: ReadAt> Future for ReadAtImpl<'a, T> {
+    type Output = io::Result<usize>;
+
+    fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
+        unsafe { self.map_unchecked_mut(|this| &mut this.state).poll(cx) }
+    }
+}
+
+enum ReadAtState<'a, T: ReadAt> {
     Invalid,
     New(&'a T, &'a mut [u8], u64),
     Pending(&'a T, ReadAtOperation<'a>),
-    Ready(io::Result<usize>),
 }
 
-impl<T: ReadAt> ReadAtImpl<'_, T> {
+impl<T: ReadAt> ReadAtState<'_, T> {
     fn take(&mut self) -> Self {
-        std::mem::replace(self, ReadAtImpl::Invalid)
+        std::mem::replace(self, ReadAtState::Invalid)
     }
 }
 
-impl<'a, T: ReadAt> Future for ReadAtImpl<'a, T> {
+impl<'a, T: ReadAt> Future for ReadAtState<'a, T> {
     type Output = io::Result<usize>;
 
     fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
         let this = unsafe { Pin::into_inner_unchecked(self) };
         loop {
             match match this.take() {
-                ReadAtImpl::New(reader, buf, offset) => {
+                ReadAtState::New(reader, buf, offset) => {
                     let pin = unsafe { Pin::new_unchecked(reader) };
                     (pin.start_read_at(cx, buf, offset), reader)
                 }
-                ReadAtImpl::Pending(reader, op) => {
+                ReadAtState::Pending(reader, op) => {
                     let pin = unsafe { Pin::new_unchecked(reader) };
                     (pin.poll_complete(op), reader)
                 }
-                ReadAtImpl::Ready(out) => return Poll::Ready(out),
-                ReadAtImpl::Invalid => panic!("poll after ready"),
+                ReadAtState::Invalid => panic!("poll after ready"),
             } {
                 (MaybeReady::Ready(out), _reader) => return Poll::Ready(out),
-                (MaybeReady::Pending(op), reader) => *this = ReadAtImpl::Pending(reader, op),
+                (MaybeReady::Pending(op), reader) => *this = ReadAtState::Pending(reader, op),
             }
         }
     }