Skip to main content

AsPath

Trait AsPath 

Source
pub trait AsPath {
    // Required method
    fn as_path(&self) -> &Path;
}
Expand description

A trait for converting various types into a reference to a Path.

This trait is used to avoid redundant allocation of memory by providing a reference to a Path. It is implemented only for types that can either be referenced or are references to Path itself. Unlike TryIntoPath, it does not allocate memory on the heap. However, TryIntoPath is implemented for a wider range of types because it is not restricted from allocating memory. Unlike AsRef< Path >, AsPath is implemented for a wider number of types, including those that are not directly convertible to a Path using AsRef. This is because AsPath is designed to provide a more flexible interface for path-like types, accommodating various representations that can logically be treated as paths.

Required Methods§

Source

fn as_path(&self) -> &Path

Converts the implementing type into a reference to a Path.

§Returns

A reference to a Path.

Implementations on Foreign Types§

Source§

impl AsPath for str

Implementation of AsPath for str.

Source§

fn as_path(&self) -> &Path

Implementors§

Source§

impl AsPath for Path

Implementation of AsPath for Path.

Source§

impl AsPath for Utf8Path

Available on crate feature path_utf8 only.

Implementation of AsPath for Utf8Path.

Source§

impl<T> AsPath for T
where T: AsRef<Path>,

Blanket implementation of AsPath for all types that implement AsRef< Path >.