dirbuf

Struct DirBuf

Source
pub struct DirBuf { /* private fields */ }
Expand description

Reusable directory buffer.

While the state of the internal buffer may change, semantically, it always has the same value as when it was constructed. This is to prevent you from accidentally making a permenant modification to its path instead of a temporary one.

Implementations§

Source§

impl DirBuf

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Source§

impl DirBuf

Source

pub fn with_capacity(capacity: usize) -> Self

Initialize an empty DirBuf with the given capacity.

Source

pub fn into_inner(self) -> PathBuf

Return the internal buffer, resetting it to its initial state first.

Source§

impl DirBuf

Source

pub fn join(&mut self, path: impl AsRef<Path>) -> DirBufEntry<'_>

Efficiently join a path with another.

The returned DirBufEntry reuses the underlying buffer, and must be dropped before join can be called again. The DirBufEntry holds a mutable reference to ensure join cannot be called before the DirBufEntry is dropped.

If the path segment is coming from untrusted user data and panics are undesirable, use try_join instead.

§Panics

Panics if path is not a trivial path.

§Performance

The overhead of the panic check is not insubstaintial. When multiple joins are used, this is still usually faster than using a PathBuf, but if you know the path is trivial (e.g. if it is a string literal), consider using join_unchecked to remove this overhead.

A trivial path can be joined to any path via a simple append.

Things that make a path non-trivial:

  • .. components
  • windows drive prefixes
  • windows verbatim paths
  • being an absolute path
Source

pub fn join_lit(&mut self, path: &str) -> DirBufEntry<'_>

Variant of join optimized for string literals.

Semantic behavior is identical to Self::join, the only difference is performance.

For simple cases, this can have performance equivelent to that of Self::join_unchecked without the unsaftey, but for more complex cases, Self::join may be more performant.

It achives this performance gain by leveraging inlining and constant folding.

Source

pub fn try_join( &mut self, path: impl AsRef<Path>, ) -> Result<DirBufEntry<'_>, JoinError>

Attempt to join a path with another.

The returned DirBufEntry reuses the underlying buffer, and must be dropped before join can be called again. The DirBufEntry holds a mutable reference to ensure join cannot be called before the DirBufEntry is dropped.

§Panics

Panics if path is not a trivial path.

A trivial path can be joined to any path via a simple append.

Things that make a path non-trivial:

  • .. components
  • windows drive prefixes
  • windows verbatim paths
  • being an absolute path
Source

pub unsafe fn join_unchecked( &mut self, path: impl AsRef<Path>, ) -> DirBufEntry<'_>

Join a path to another without checking that it is trivial.

§Saftey

path must be a trivial path.

A trivial path can be joined to any path via a simple append.

Things that make a path non-trivial:

  • .. components
  • windows drive prefixes
  • windows verbatim paths
  • being an absolute path

Trait Implementations§

Source§

impl AsRef<Path> for DirBuf

Source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for DirBuf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DirBuf

Source§

fn default() -> DirBuf

Returns the “default value” for a type. Read more
Source§

impl<T: AsRef<Path>> PartialEq<T> for DirBuf

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for DirBuf

§

impl RefUnwindSafe for DirBuf

§

impl Send for DirBuf

§

impl Sync for DirBuf

§

impl Unpin for DirBuf

§

impl UnwindSafe for DirBuf

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.