Struct shlex::bytes::Quoter

source ·
pub struct Quoter { /* private fields */ }
Expand description

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§

source§

impl Quoter

source

pub fn new() -> Self

Create a new Quoter with default settings.

source

pub fn allow_nul(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.

source

pub fn join<'a, I: IntoIterator<Item = &'a [u8]>>( &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.

source

pub fn quote<'a>(&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.

Trait Implementations§

source§

impl Clone for Quoter

source§

fn clone(&self) -> Quoter

Returns a copy 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 Debug for Quoter

source§

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

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

impl Default for Quoter

source§

fn default() -> Quoter

Returns the “default value” for a type. Read more
source§

impl From<Quoter> for Quoter

source§

fn from(quoter: Quoter) -> Quoter

Converts to this type from the input type.
source§

impl From<Quoter> for Quoter

source§

fn from(inner: Quoter) -> Quoter

Converts to this type from the input type.

Auto Trait Implementations§

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> 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> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.