Skip to main content

PathUtf8Encoder

Trait PathUtf8Encoder 

Source
pub trait PathUtf8Encoder {
    // Required method
    fn to_utf8_string(&self) -> String;
}
Expand description

Extension trait for encoding paths to UTF-8 strings.

This is a separate trait from Utf8Encoder due to Rust’s coherence rules preventing blanket implementations from coexisting with specific type implementations.

Required Methods§

Source

fn to_utf8_string(&self) -> String

Converts a path to a UTF-8 string, replacing invalid bytes with fallback characters.

§Example
use ps_str::PathUtf8Encoder;
use std::path::Path;

let path = Path::new("hello.txt");
let encoded = path.to_utf8_string();
assert_eq!(encoded, "hello.txt");

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PathUtf8Encoder for Path

Source§

impl PathUtf8Encoder for PathBuf

Implementors§