sanitise_file_name

Trait Stringy

Source
pub trait Stringy:
    Index<Range<usize>, Output = str>
    + Index<RangeFrom<usize>, Output = str>
    + Deref<Target = str>
    + Extend<char> {
    // Required methods
    fn push(&mut self, ch: char);
    fn push_str(&mut self, string: &str);
    fn pop(&mut self) -> Option<char>;
    fn truncate(&mut self, new_len: usize);
    fn replace_range<R>(&mut self, range: R, replace_with: &str)
       where R: RangeBounds<usize>;
}
Expand description

A target for sanitisation: essentially the subset of String functionality used.

It might have been nice to use something like Read + Write + Seek instead, but the need to delete things after writing means that you need still more, and in the end it’s much easier to treat it as a string.

I’ve provided implementations for String (if the alloc feature is enabled, which it is by default) and tinyvec_string::ArrayString (if the tinyvec_string feature is enabled), but there’s nothing preventing you from implementing it on other similar string types.

Required Methods§

Source

fn push(&mut self, ch: char)

Source

fn push_str(&mut self, string: &str)

Source

fn pop(&mut self) -> Option<char>

Source

fn truncate(&mut self, new_len: usize)

Source

fn replace_range<R>(&mut self, range: R, replace_with: &str)
where R: RangeBounds<usize>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Stringy for String

Available on crate feature alloc only.
Source§

fn push(&mut self, ch: char)

Source§

fn push_str(&mut self, string: &str)

Source§

fn pop(&mut self) -> Option<char>

Source§

fn truncate(&mut self, new_len: usize)

Source§

fn replace_range<R>(&mut self, range: R, replace_with: &str)
where R: RangeBounds<usize>,

Source§

impl<A: ByteArray> Stringy for ArrayString<A>

Available on crate feature tinyvec_string only.
Source§

fn push(&mut self, ch: char)

Source§

fn push_str(&mut self, string: &str)

Source§

fn pop(&mut self) -> Option<char>

Source§

fn truncate(&mut self, new_len: usize)

Source§

fn replace_range<R>(&mut self, range: R, replace_with: &str)
where R: RangeBounds<usize>,

Implementors§