From 716753f1a8215711231978b27dc7152b5b984b0c Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 13 Oct 2021 10:40:50 +0200 Subject: [PATCH] pbs-tools: drop borrow module Signed-off-by: Wolfgang Bumiller --- pbs-datastore/Cargo.toml | 1 + pbs-datastore/src/checksum_reader.rs | 3 +- pbs-datastore/src/checksum_writer.rs | 3 +- pbs-tools/Cargo.toml | 1 + pbs-tools/src/borrow.rs | 59 ---------------------------- pbs-tools/src/fs.rs | 3 +- pbs-tools/src/lib.rs | 1 - 7 files changed, 7 insertions(+), 64 deletions(-) delete mode 100644 pbs-tools/src/borrow.rs diff --git a/pbs-datastore/Cargo.toml b/pbs-datastore/Cargo.toml index 8d53e995..aae58260 100644 --- a/pbs-datastore/Cargo.toml +++ b/pbs-datastore/Cargo.toml @@ -26,6 +26,7 @@ pathpatterns = "0.1.2" pxar = "0.10.1" proxmox = "0.14.0" +proxmox-borrow = "1" proxmox-io = "1" proxmox-lang = "1" proxmox-schema = { version = "1", features = [ "api-macro" ] } diff --git a/pbs-datastore/src/checksum_reader.rs b/pbs-datastore/src/checksum_reader.rs index 7bf8f34d..a1a508bd 100644 --- a/pbs-datastore/src/checksum_reader.rs +++ b/pbs-datastore/src/checksum_reader.rs @@ -2,7 +2,8 @@ use anyhow::{Error}; use std::sync::Arc; use std::io::Read; -use pbs_tools::borrow::Tied; +use proxmox_borrow::Tied; + use pbs_tools::crypt_config::CryptConfig; pub struct ChecksumReader { diff --git a/pbs-datastore/src/checksum_writer.rs b/pbs-datastore/src/checksum_writer.rs index 3c502ddd..ea9e1b9e 100644 --- a/pbs-datastore/src/checksum_writer.rs +++ b/pbs-datastore/src/checksum_writer.rs @@ -3,7 +3,8 @@ use std::io::Write; use anyhow::{Error}; -use pbs_tools::borrow::Tied; +use proxmox_borrow::Tied; + use pbs_tools::crypt_config::CryptConfig; pub struct ChecksumWriter { diff --git a/pbs-tools/Cargo.toml b/pbs-tools/Cargo.toml index 5c87c065..439069ff 100644 --- a/pbs-tools/Cargo.toml +++ b/pbs-tools/Cargo.toml @@ -33,6 +33,7 @@ walkdir = "2" zstd = { version = "0.6", features = [ "bindgen" ] } proxmox = { version = "0.14.0", default-features = false, features = [ "tokio" ] } +proxmox-borrow = "1" proxmox-io = { version = "1", features = [ "tokio" ] } proxmox-lang = { version = "1" } proxmox-time = { version = "1" } diff --git a/pbs-tools/src/borrow.rs b/pbs-tools/src/borrow.rs deleted file mode 100644 index 66b68ada..00000000 --- a/pbs-tools/src/borrow.rs +++ /dev/null @@ -1,59 +0,0 @@ -/// This ties two values T and U together, such that T does not move and cannot be used as long as -/// there's an U. This essentially replaces the borrow checker's job for dependent values which -/// need to be stored together in a struct {}, and is similar to what the 'rental' crate produces. -pub struct Tied(Option>, Option>); - -impl Drop for Tied { - fn drop(&mut self) { - // let's be explicit about order here! - std::mem::drop(self.1.take()); - } -} - -impl Tied { - /// Takes an owner and a function producing the depending value. The owner will be inaccessible - /// until the tied value is resolved. The dependent value is only accessible by reference. - pub fn new(owner: T, producer: F) -> Self - where - F: FnOnce(*mut T) -> Box, - { - let mut owner = Box::new(owner); - let dep = producer(&mut *owner); - Tied(Some(owner), Some(dep)) - } - - pub fn into_boxed_inner(mut self) -> Box { - self.1 = None; - self.0.take().unwrap() - } - - pub fn into_inner(self) -> T { - *self.into_boxed_inner() - } -} - -impl AsRef for Tied { - fn as_ref(&self) -> &U { - self.1.as_ref().unwrap() - } -} - -impl AsMut for Tied { - fn as_mut(&mut self) -> &mut U { - self.1.as_mut().unwrap() - } -} - -impl std::ops::Deref for Tied { - type Target = U; - - fn deref(&self) -> &U { - self.as_ref() - } -} - -impl std::ops::DerefMut for Tied { - fn deref_mut(&mut self) -> &mut U { - self.as_mut() - } -} diff --git a/pbs-tools/src/fs.rs b/pbs-tools/src/fs.rs index 4af75e1d..9ae2389d 100644 --- a/pbs-tools/src/fs.rs +++ b/pbs-tools/src/fs.rs @@ -18,8 +18,7 @@ use nix::sys::stat::Mode; use regex::Regex; use proxmox::sys::error::SysError; - -use crate::borrow::Tied; +use proxmox_borrow::Tied; pub type DirLockGuard = Dir; diff --git a/pbs-tools/src/lib.rs b/pbs-tools/src/lib.rs index 8ac322dd..f36cc175 100644 --- a/pbs-tools/src/lib.rs +++ b/pbs-tools/src/lib.rs @@ -1,6 +1,5 @@ pub mod acl; pub mod blocking; -pub mod borrow; pub mod broadcast_future; pub mod cert; pub mod cli;