pbs-tools: drop borrow module
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
b3f279e2d9
commit
5a8726e6d2
|
@ -26,6 +26,7 @@ pathpatterns = "0.1.2"
|
||||||
pxar = "0.10.1"
|
pxar = "0.10.1"
|
||||||
|
|
||||||
proxmox = "0.14.0"
|
proxmox = "0.14.0"
|
||||||
|
proxmox-borrow = "1"
|
||||||
proxmox-io = "1"
|
proxmox-io = "1"
|
||||||
proxmox-lang = "1"
|
proxmox-lang = "1"
|
||||||
proxmox-schema = { version = "1", features = [ "api-macro" ] }
|
proxmox-schema = { version = "1", features = [ "api-macro" ] }
|
||||||
|
|
|
@ -2,7 +2,8 @@ use anyhow::{Error};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use pbs_tools::borrow::Tied;
|
use proxmox_borrow::Tied;
|
||||||
|
|
||||||
use pbs_tools::crypt_config::CryptConfig;
|
use pbs_tools::crypt_config::CryptConfig;
|
||||||
|
|
||||||
pub struct ChecksumReader<R> {
|
pub struct ChecksumReader<R> {
|
||||||
|
|
|
@ -3,7 +3,8 @@ use std::io::Write;
|
||||||
|
|
||||||
use anyhow::{Error};
|
use anyhow::{Error};
|
||||||
|
|
||||||
use pbs_tools::borrow::Tied;
|
use proxmox_borrow::Tied;
|
||||||
|
|
||||||
use pbs_tools::crypt_config::CryptConfig;
|
use pbs_tools::crypt_config::CryptConfig;
|
||||||
|
|
||||||
pub struct ChecksumWriter<W> {
|
pub struct ChecksumWriter<W> {
|
||||||
|
|
|
@ -33,6 +33,7 @@ walkdir = "2"
|
||||||
zstd = { version = "0.6", features = [ "bindgen" ] }
|
zstd = { version = "0.6", features = [ "bindgen" ] }
|
||||||
|
|
||||||
proxmox = { version = "0.14.0", default-features = false, features = [ "tokio" ] }
|
proxmox = { version = "0.14.0", default-features = false, features = [ "tokio" ] }
|
||||||
|
proxmox-borrow = "1"
|
||||||
proxmox-io = { version = "1", features = [ "tokio" ] }
|
proxmox-io = { version = "1", features = [ "tokio" ] }
|
||||||
proxmox-lang = { version = "1" }
|
proxmox-lang = { version = "1" }
|
||||||
proxmox-time = { version = "1" }
|
proxmox-time = { version = "1" }
|
||||||
|
|
|
@ -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<T, U: ?Sized>(Option<Box<T>>, Option<Box<U>>);
|
|
||||||
|
|
||||||
impl<T, U: ?Sized> Drop for Tied<T, U> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
// let's be explicit about order here!
|
|
||||||
std::mem::drop(self.1.take());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U: ?Sized> Tied<T, U> {
|
|
||||||
/// 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<F>(owner: T, producer: F) -> Self
|
|
||||||
where
|
|
||||||
F: FnOnce(*mut T) -> Box<U>,
|
|
||||||
{
|
|
||||||
let mut owner = Box::new(owner);
|
|
||||||
let dep = producer(&mut *owner);
|
|
||||||
Tied(Some(owner), Some(dep))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_boxed_inner(mut self) -> Box<T> {
|
|
||||||
self.1 = None;
|
|
||||||
self.0.take().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_inner(self) -> T {
|
|
||||||
*self.into_boxed_inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U: ?Sized> AsRef<U> for Tied<T, U> {
|
|
||||||
fn as_ref(&self) -> &U {
|
|
||||||
self.1.as_ref().unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U: ?Sized> AsMut<U> for Tied<T, U> {
|
|
||||||
fn as_mut(&mut self) -> &mut U {
|
|
||||||
self.1.as_mut().unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U: ?Sized> std::ops::Deref for Tied<T, U> {
|
|
||||||
type Target = U;
|
|
||||||
|
|
||||||
fn deref(&self) -> &U {
|
|
||||||
self.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U: ?Sized> std::ops::DerefMut for Tied<T, U> {
|
|
||||||
fn deref_mut(&mut self) -> &mut U {
|
|
||||||
self.as_mut()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,8 +16,7 @@ use nix::sys::stat::Mode;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use proxmox::sys::error::SysError;
|
use proxmox::sys::error::SysError;
|
||||||
|
use proxmox_borrow::Tied;
|
||||||
use crate::borrow::Tied;
|
|
||||||
|
|
||||||
pub type DirLockGuard = Dir;
|
pub type DirLockGuard = Dir;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod acl;
|
pub mod acl;
|
||||||
pub mod blocking;
|
pub mod blocking;
|
||||||
pub mod borrow;
|
|
||||||
pub mod broadcast_future;
|
pub mod broadcast_future;
|
||||||
pub mod cert;
|
pub mod cert;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
|
|
Loading…
Reference in New Issue