Path

Struct Path 

Source
pub struct Path {}
Expand description

Helper struct for file path operations.

Implementations§

Source§

impl Path

Source

pub fn get_ext(path: &str) -> String

Extracts the file extension from a given file path.

§Example

Input: “/a/b/c.TXT” Output: “txt”

§Arguments
  • path - The input file path.
§Returns
  • String - The extension of the input file.
Source

pub fn get_path(path: &str) -> String

Extracts the parent path from a given file path.

§Example

Input: “/a/b/c.TXT” Output: “/a/b”

§Arguments
  • path - The input file path.
§Returns
  • String - The parent path of the input file.
Source

pub fn get_name(path: &str) -> String

Extracts the file name without extension from a given file path.

§Example

Input: “/a/b/c.TXT” Output: “c”

§Arguments
  • path - The input file path.
§Returns
  • String - The name of the input file without extension.
Source

pub fn get_filename(path: &str) -> String

Extracts the file name from a given file path.

§Example

Input: “/a/b/c.TXT” Output: “c.TXT”

§Arguments
  • path - The input file path.
§Returns
  • String - The name of the input file.
Source

pub fn get_relative(path: &str, target: &str) -> String

Computes the relative path from the target file to the input file.

§Example

Input: “/a/b/c.TXT”, base: “/a” Output: “b/c.TXT”

§Arguments
  • path - The input file path.
  • base - The target file path.
§Returns
  • String - The relative path from the input file to the target file.
Source

pub fn replace_ext(path: &str, new_ext: &str) -> String

Changes the file extension in a given file path.

§Example

Input: “/a/b/c.TXT”, “lua” Output: “/a/b/c.lua”

§Arguments
  • path - The input file path.
  • new_ext - The new file extension to replace the old one.
§Returns
  • String - The new file path.
Source

pub fn replace_filename(path: &str, new_file: &str) -> String

Changes the filename in a given file path.

§Example

Input: “/a/b/c.TXT”, “d” Output: “/a/b/d.TXT”

§Arguments
  • path - The input file path.
  • new_file - The new filename to replace the old one.
§Returns
  • String - The new file path.
Source

pub fn concat(paths: &Vec<&str>) -> String

Joins the given segments into a new file path.

§Example

Input: “a”, “b”, “c.TXT” Output: “a/b/c.TXT”

§Arguments
  • segments - The segments to be joined as a new file path.
§Returns
  • String - The new file path.

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

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.