]> git.proxmox.com Git - pxar.git/commitdiff
add EncoderOutput::to_borrowed()
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 17 Feb 2021 08:50:10 +0000 (09:50 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 17 Feb 2021 08:51:38 +0000 (09:51 +0100)
may more "explicit" than using `.as_mut().into()`, but
otherwise just seems like a useful addition to show the
lifetime constraints on this

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/encoder/mod.rs

index 428a5c56234cd894d328c23026d92dece2a5f9fa..92e79c24c1ce623bec6672665ee3a07d7656eea5 100644 (file)
@@ -221,10 +221,20 @@ pub(crate) enum EncoderOutput<'a, T> {
     Borrowed(&'a mut T),
 }
 
+impl<'a, T> EncoderOutput<'a, T> {
+    #[inline]
+    fn to_borrowed<'s>(&'s mut self) -> EncoderOutput<'s, T>
+    where
+        'a: 's,
+    {
+        EncoderOutput::Borrowed(self.as_mut())
+    }
+}
+
 impl<'a, T> std::convert::AsMut<T> for EncoderOutput<'a, T> {
     fn as_mut(&mut self) -> &mut T {
         match self {
-            EncoderOutput::Owned(ref mut o) => o,
+            EncoderOutput::Owned(o) => o,
             EncoderOutput::Borrowed(b) => b,
         }
     }
@@ -273,7 +283,7 @@ impl<'a, T: SeqWrite + 'a> Drop for EncoderImpl<'a, T> {
 }
 
 impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
-    pub(crate) async fn new(output: EncoderOutput<'a, T>, metadata: &Metadata) -> io::Result<EncoderImpl<'a, T>> {
+    pub async fn new(output: EncoderOutput<'a, T>, metadata: &Metadata) -> io::Result<EncoderImpl<'a, T>> {
         if !metadata.is_dir() {
             io_bail!("directory metadata must contain the directory mode flag");
         }
@@ -536,7 +546,7 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
 
         Ok(EncoderImpl {
             // always forward as Borrowed(), to avoid stacking references on nested calls
-            output: self.output.as_mut().into(),
+            output: self.output.to_borrowed(),
             state: EncoderState {
                 entry_offset,
                 files_offset,