Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cap-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ edition = "2021"
ambient-authority = "0.0.2"
arbitrary = { version = "1.0.0", optional = true, features = ["derive"] }
ipnet = "2.5.0"
maybe-owned = "0.3.4"
fs-set-times = "0.20.0"
io-extras = "0.19.0"
io-lifetimes = { version = "3.0.1", default-features = false }
Expand Down
23 changes: 22 additions & 1 deletion cap-primitives/src/fs/maybe_owned_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::fs::{open_unchecked, OpenOptions};
use maybe_owned::MaybeOwned;
use std::ops::Deref;
use std::path::Component;
use std::{fmt, fs, io, mem};
Expand Down Expand Up @@ -27,6 +26,28 @@ pub(super) struct MaybeOwnedFile<'borrow> {
path: Option<PathBuf>,
}

enum MaybeOwned<'a, T: 'a> {
Owned(T),
Borrowed(&'a T),
}

impl<T> Deref for MaybeOwned<'_, T> {
type Target = T;

fn deref(&self) -> &T {
match self {
Self::Owned(v) => v,
Self::Borrowed(v) => v,
}
}
}

impl<T> AsRef<T> for MaybeOwned<'_, T> {
fn as_ref(&self) -> &T {
self
}
}

impl<'borrow> MaybeOwnedFile<'borrow> {
/// Constructs a new `MaybeOwnedFile` which is not owned.
pub(super) fn borrowed(file: &'borrow fs::File) -> Self {
Expand Down
Loading