Struct Quoter

struct Quoter { ... }

A more configurable interface to quote strings. If you only want the default settings you can use the convenience functions try_quote and try_join.

The string equivalent is shlex::Quoter.

Implementations

impl Quoter

fn new() -> Self

Create a new Quoter with default settings.

fn allow_nul(self: Self, allow: bool) -> Self

Set whether to allow nul bytes. By default they are not allowed and will result in an error of QuoteError::Nul.

fn join<'a, I: IntoIterator<Item = &'a [u8]>>(self: &Self, words: I) -> Result<Vec<u8>, QuoteError>

Convenience function that consumes an iterable of words and turns it into a single byte string, quoting words when necessary. Consecutive words will be separated by a single space.

fn quote<'a>(self: &Self, in_bytes: &'a [u8]) -> Result<Cow<'a, [u8]>, QuoteError>

Given a single word, return a byte string suitable to encode it as a shell argument.

If given valid UTF-8, this will never produce invalid UTF-8. This is because it only ever inserts valid ASCII characters before or after existing ASCII characters (or returns two single quotes if the input was an empty string). It will never modify a multibyte UTF-8 character.

impl Clone for Quoter

fn clone(self: &Self) -> Quoter

impl Debug for Quoter

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

impl Default for Quoter

fn default() -> Quoter

impl Freeze for Quoter

impl From for Quoter

fn from(quoter: Quoter) -> Quoter

impl RefUnwindSafe for Quoter

impl Send for Quoter

impl Sync for Quoter

impl Unpin for Quoter

impl UnsafeUnpin for Quoter

impl UnwindSafe for Quoter

impl<T> Any for Quoter

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Quoter

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Quoter

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Quoter

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Quoter

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Quoter

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Quoter

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Quoter

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Quoter

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>