PathBufExt

Trait PathBufExt 

Source
pub trait PathBufExt {
    // Required method
    fn sanitise_filename(&mut self, to: &str) -> Option<bool>;
}
Expand description

Extension trait for std::path::PathBuf.

Required Methods§

Source

fn sanitise_filename(&mut self, to: &str) -> Option<bool>

Replaces banned characters in the file name with the given replacement.

Returns None if the path does not have a file name, Some(true) if the file name was sanitised, or Some(false) if the file name could not be sanitised due to containing invalid UTF-8.

§Example
use ntfsanitise::{PathExt, PathBufExt};
use std::ffi::OsString;
use std::path::PathBuf;

let mut path = PathBuf::from("/example/<name>.txt");
assert!(path.is_dirty());

path.sanitise_filename("_");
let expected = OsString::from("_name_.txt");
let expected = expected.as_os_str();

assert_eq!(path.file_name(), Some(expected));
assert!(path.is_clean());

Implementations on Foreign Types§

Source§

impl PathBufExt for PathBuf

Source§

fn sanitise_filename(&mut self, to: &str) -> Option<bool>

Implementors§