]> git.proxmox.com Git - pxar.git/commitdiff
accessr: add convenience read_at to FileContents
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 18 May 2020 13:25:05 +0000 (15:25 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 18 May 2020 13:25:05 +0000 (15:25 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/accessor/aio.rs

index c457bb98ea503ea6e62364e338d9c7a1e240c7e1..5955eaf2b288c80e10547c2c34a39508963de700 100644 (file)
@@ -15,6 +15,7 @@ use std::task::{Context, Poll};
 use crate::accessor::{self, cache::Cache, ReadAt};
 use crate::decoder::Decoder;
 use crate::format::GoodbyeItem;
+use crate::poll_fn::poll_fn;
 use crate::Entry;
 
 use super::sync::{FileReader, FileRefReader};
@@ -349,3 +350,11 @@ impl<T: Clone + ReadAt> ReadAt for FileContents<T> {
         unsafe { self.map_unchecked(|this| &this.inner) }.poll_read_at(cx, buf, offset)
     }
 }
+
+impl<T: Clone + ReadAt> FileContents<T> {
+    /// Convenience helper for `read_at`:
+    pub async fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
+        let this = unsafe { Pin::new_unchecked(self) };
+        poll_fn(move |cx| this.poll_read_at(cx, buf, offset)).await
+    }
+}