From 013752cb3c0f87f2476a43dac83e6f621fd57e34 Mon Sep 17 00:00:00 2001 From: Expyron <5100376+Expyron@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:39:43 +0200 Subject: [PATCH] Remove `maybe-owned` dependency --- cap-primitives/Cargo.toml | 1 - cap-primitives/src/fs/maybe_owned_file.rs | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cap-primitives/Cargo.toml b/cap-primitives/Cargo.toml index eb49b285..708049d7 100644 --- a/cap-primitives/Cargo.toml +++ b/cap-primitives/Cargo.toml @@ -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 } diff --git a/cap-primitives/src/fs/maybe_owned_file.rs b/cap-primitives/src/fs/maybe_owned_file.rs index 443cba24..91203f81 100644 --- a/cap-primitives/src/fs/maybe_owned_file.rs +++ b/cap-primitives/src/fs/maybe_owned_file.rs @@ -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}; @@ -27,6 +26,28 @@ pub(super) struct MaybeOwnedFile<'borrow> { path: Option, } +enum MaybeOwned<'a, T: 'a> { + Owned(T), + Borrowed(&'a T), +} + +impl Deref for MaybeOwned<'_, T> { + type Target = T; + + fn deref(&self) -> &T { + match self { + Self::Owned(v) => v, + Self::Borrowed(v) => v, + } + } +} + +impl AsRef 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 {