Sha256: 1b3c28bf02aad1e211475a6628f4826919456c5065cc5aaa11606f88463af84e

Contents?: true

Size: 1.52 KB

Versions: 39

Compression:

Stored size: 1.52 KB

Contents

use std::borrow::Cow;
use std::ffi::OsStr;
use std::path::Component;

/// Like `std::path::Component` except we combine `Prefix` and `RootDir` since
/// we don't support absolute paths, and `Normal` has a `Cow` instead of a
/// plain `OsStr` reference, so it can optionally own its own string.
pub(super) enum CowComponent<'borrow> {
    PrefixOrRootDir,
    CurDir,
    ParentDir,
    Normal(Cow<'borrow, OsStr>),
}

impl<'borrow> CowComponent<'borrow> {
    /// Convert a `Component` into a `CowComponent` which borrows strings.
    pub(super) fn borrowed(component: Component<'borrow>) -> Self {
        match component {
            Component::Prefix(_) | Component::RootDir => Self::PrefixOrRootDir,
            Component::CurDir => Self::CurDir,
            Component::ParentDir => Self::ParentDir,
            Component::Normal(os_str) => Self::Normal(os_str.into()),
        }
    }

    /// Convert a `Component` into a `CowComponent` which owns strings.
    pub(super) fn owned(component: Component) -> Self {
        match component {
            Component::Prefix(_) | Component::RootDir => Self::PrefixOrRootDir,
            Component::CurDir => Self::CurDir,
            Component::ParentDir => Self::ParentDir,
            Component::Normal(os_str) => Self::Normal(os_str.to_os_string().into()),
        }
    }

    /// Test whether `self` is `Component::Normal`.
    #[cfg(windows)]
    pub(super) fn is_normal(&self) -> bool {
        match self {
            CowComponent::Normal(_) => true,
            _ => false,
        }
    }
}

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/cap-primitives-3.4.2/src/fs/manually/cow_component.rs
wasmtime-29.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/fs/manually/cow_component.rs
wasmtime-28.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/fs/manually/cow_component.rs
wasmtime-27.0.0 ./ext/cargo-vendor/cap-primitives-3.4.1/src/fs/manually/cow_component.rs
wasmtime-26.0.0 ./ext/cargo-vendor/cap-primitives-3.3.0/src/fs/manually/cow_component.rs
wasmtime-25.0.2 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/manually/cow_component.rs
wasmtime-25.0.1 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/manually/cow_component.rs
wasmtime-25.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/manually/cow_component.rs
wasmtime-24.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/manually/cow_component.rs
wasmtime-23.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/manually/cow_component.rs
wasmtime-22.0.0 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/manually/cow_component.rs
wasmtime-21.0.1 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/manually/cow_component.rs
wasmtime-20.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/manually/cow_component.rs
wasmtime-20.0.0 ./ext/cargo-vendor/cap-primitives-3.0.0/src/fs/manually/cow_component.rs
wasmtime-18.0.3 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/manually/cow_component.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/manually/cow_component.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/manually/cow_component.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/manually/cow_component.rs
wasmtime-15.0.1 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/manually/cow_component.rs
wasmtime-15.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/manually/cow_component.rs