FilePath

Struct FilePath 

Source
pub struct FilePath<T> { /* private fields */ }
Expand description

Generic file path value object with type-safe path categories

§Purpose

Type-safe file path that provides:

  • Compile-time path category enforcement (Input vs Output vs Temp)
  • Shared validation and utility methods
  • Zero-cost abstractions with phantom types
  • Extensible design for new path categories

§Generic Benefits

  • Type Safety: Cannot mix input and output paths at compile time
  • Code Reuse: Shared implementation for all path types
  • Extensibility: Easy to add new path categories
  • Zero Cost: Phantom types have no runtime overhead

§Use Cases

  • Pipeline input/output path specification
  • Temporary file management
  • Configuration file paths
  • Log file paths

§Cross-Language Mapping

  • Rust: FilePath<T> with marker types

§Examples

  • Go: Separate types with shared interface
  • JSON: String representation with type hints
  • SQLite: TEXT column with category metadata

Implementations§

Source§

impl<T: PathCategory> FilePath<T>

Source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, PipelineError>

Creates a new file path with category-specific validation

§Purpose

Creates a type-safe file path with compile-time category enforcement. Uses phantom types to prevent mixing different path categories at compile time. # Why Type-safe paths provide:

  • Compile-time prevention of input/output path mixing
  • Category-specific validation rules
  • Zero-cost abstractions with phantom types
  • Clear API contracts for path requirements
§Arguments
  • path - Path to validate (can be &str, String, Path, PathBuf)
§Returns
  • Ok(FilePath<T>) - Validated path with category type
  • Err(PipelineError::InvalidConfiguration) - Validation failed
§Errors

Returns PipelineError::InvalidConfiguration when:

  • Path is empty
  • Path contains null bytes
  • Path exceeds 4096 characters
  • Category-specific validation fails
§Examples
Source

pub fn parse(path: &str) -> Result<Self, PipelineError>

Creates a file path from a string

Source

pub fn as_path(&self) -> &Path

Gets the underlying path

Source

pub fn to_path_buf(&self) -> PathBuf

Gets the path as a PathBuf

Source

pub fn to_string_lossy(&self) -> String

Gets the path as a string

Source

pub fn file_name(&self) -> Option<&str>

Gets the file name component

Source

pub fn file_stem(&self) -> Option<&str>

Gets the file stem (name without extension)

Source

pub fn extension(&self) -> Option<&str>

Gets the file extension

Source

pub fn parent(&self) -> Option<FilePath<T>>

Gets the parent directory

Source

pub fn exists(&self) -> bool

Checks if the path exists

Source

pub fn is_file(&self) -> bool

Checks if the path is a file

Source

pub fn is_dir(&self) -> bool

Checks if the path is a directory

Source

pub fn category(&self) -> &'static str

Gets the path category name

Source

pub fn into_category<U: PathCategory>( self, ) -> Result<FilePath<U>, PipelineError>

Converts to a different path category (type conversion)

§Purpose

Safely converts a path from one category to another with validation. Useful when a path needs to be used in a different context.

§Why

Category conversion enables:

  • Reusing paths across different contexts
  • Type-safe path transformations
  • Validation of new category requirements
  • Flexible path handling
§Type Parameters
  • U - Target path category (must implement PathCategory)
§Returns
  • Ok(FilePath<U>) - Converted path with new category
  • Err(PipelineError) - Target category validation failed
§Errors

Returns PipelineError if the path doesn’t meet the target category’s validation requirements.

§Examples
Source

pub fn with_extension(&self, extension: &str) -> FilePath<T>

Creates a path with a different extension

Source

pub fn join<P: AsRef<Path>>(&self, path: P) -> FilePath<T>

Joins with another path component

Source

pub fn validate(&self) -> Result<(), PipelineError>

Validates the file path with category-specific rules

Source§

impl FilePath<InputMarker>

Specialized constructors for different path types

Source

pub fn existing<P: AsRef<Path>>(path: P) -> Result<Self, PipelineError>

Creates an input path that must exist

Source

pub fn with_required_extension<P: AsRef<Path>>( path: P, ext: &str, ) -> Result<Self, PipelineError>

Creates an input path with required extension

Source§

impl FilePath<OutputMarker>

Source

pub fn with_parent_creation<P: AsRef<Path>>( path: P, ) -> Result<Self, PipelineError>

Creates an output path, ensuring parent directory exists

Source

pub fn create_backup(&self) -> Result<OutputPath, PipelineError>

Creates a backup of an existing output path

Source§

impl FilePath<TempMarker>

Source

pub fn unique(prefix: &str, extension: &str) -> Result<Self, PipelineError>

Creates a temporary path with unique name

Source

pub fn auto_cleanup( prefix: &str, extension: &str, ) -> Result<AutoCleanupTempPath, PipelineError>

Creates a temporary path that will be automatically cleaned up

Trait Implementations§

Source§

impl<T> AsRef<Path> for FilePath<T>

Source§

fn as_ref(&self) -> &Path

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

impl<T: Clone> Clone for FilePath<T>

Source§

fn clone(&self) -> FilePath<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for FilePath<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for FilePath<T>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for FilePath<T>
where T: PathCategory,

Source§

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

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

impl<T> From<FilePath<T>> for PathBuf

Source§

fn from(file_path: FilePath<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for FilePath<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for FilePath<T>

Source§

fn eq(&self, other: &FilePath<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.
Source§

impl<T> Serialize for FilePath<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Eq> Eq for FilePath<T>

Source§

impl<T> StructuralPartialEq for FilePath<T>

Auto Trait Implementations§

§

impl<T> Freeze for FilePath<T>

§

impl<T> RefUnwindSafe for FilePath<T>
where T: RefUnwindSafe,

§

impl<T> Send for FilePath<T>
where T: Send,

§

impl<T> Sync for FilePath<T>
where T: Sync,

§

impl<T> Unpin for FilePath<T>
where T: Unpin,

§

impl<T> UnwindSafe for FilePath<T>
where T: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,