Skip to main content

OwnedPath

Struct OwnedPath 

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

OwnedPath is the equivalent of PathBuf in the normal std library. It is a path whose inner representation is a String. The path can be modified by adding other paths using the OwnedPath::push method.

Implementations§

Source§

impl OwnedPath

Source

pub fn new() -> Self

Creates a new, empty owned path.

Source

pub fn as_path(&self) -> &Path

Source

pub fn push<P: AsRef<Path>>(&mut self, segment: P)

Appends another path to the end of this path. If the other path is absolute, but this path is not empty, then the path will be appended as a relative path.

use kstd::path::owned::OwnedPath;
let mut path = OwnedPath::from("foo");
path.push("/bar");
assert_eq!(path.to_string(), "foo/bar");

Pushing a parent directory will not remove the last component of the path:

use kstd::path::owned::OwnedPath;
let mut path = OwnedPath::from("foo/bar");
path.push("..");
assert_eq!(path.to_string(), "foo/bar/..");

Pushing a root dir is a no-op if the path is not empty, otherwise it will make this path absolute.

use kstd::path::owned::OwnedPath;
let mut path = OwnedPath::new();
path.push("/");
path.push("foo");
assert_eq!(path.to_string(), "/foo");

Pushing a current dir is always a no-op and will not modify the path in any way.

Source

pub fn into_components(self) -> Vec<OwnedPath>

Converts the path into its components.

use kstd::path::owned::OwnedPath;
let mut my_root = OwnedPath::from("/my/path");
assert_eq!(vec![OwnedPath::from("my"), OwnedPath::from("path")], my_root.into_components());
Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn components(&self) -> Components<'_>

Trait Implementations§

Source§

impl Borrow<Path> for OwnedPath

Source§

fn borrow(&self) -> &Path

Immutably borrows from an owned value. Read more
Source§

impl Clone for OwnedPath

Source§

fn clone(&self) -> OwnedPath

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OwnedPath

Source§

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

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

impl Default for OwnedPath

Source§

fn default() -> Self

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

impl Display for OwnedPath

Source§

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

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

impl Eq for OwnedPath

Source§

impl<P: AsRef<Path>> From<P> for OwnedPath

Source§

fn from(v: P) -> Self

Converts to this type from the input type.
Source§

impl Ord for OwnedPath

Source§

fn cmp(&self, other: &OwnedPath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for OwnedPath

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for OwnedPath

Source§

fn partial_cmp(&self, other: &OwnedPath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for OwnedPath

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.