Struct shell_quote::Fish

source ·
pub struct Fish;
Expand description

Quote byte strings for use with fish.

The documentation on quoting and escaping characters in fish is confusing at first, especially when coming from a Bourne-like shell, but essentially we have to be able to move and and out of a quoted string context. For example, the escape sequence \t for a tab must be outside of quotes, single or double, to be recognised as a tab character by fish:

echo 'foo'\t'bar'

This emphasises the importance of using the correct quoting module for the target shell.

Implementations§

source§

impl Fish

source

pub fn quote<'a, S: ?Sized + Into<Quotable<'a>>>(s: S) -> Vec<u8>

Quote a string of bytes into a new Vec<u8>.

This will return one of the following:

  • The string as-is, if no escaping is necessary.
  • An escaped string, like 'foo \'bar', \a'ABC'

See quote_into for a variant that extends an existing Vec instead of allocating a new one.

§Examples
assert_eq!(Fish::quote("foobar"), b"foobar");
assert_eq!(Fish::quote("foo 'bar"), b"'foo \\'bar'");
source

pub fn quote_into<'a, S: ?Sized + Into<Quotable<'a>>>(s: S, sout: &mut Vec<u8>)

Quote a string of bytes into an existing Vec<u8>.

See quote for more details.

§Examples
let mut buf = Vec::with_capacity(128);
Fish::quote_into("foobar", &mut buf);
buf.push(b' ');  // Add a space.
Fish::quote_into("foo 'bar", &mut buf);
assert_eq!(buf, b"foobar 'foo \\'bar'");

Trait Implementations§

source§

impl Clone for Fish

source§

fn clone(&self) -> Fish

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 Fish

source§

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

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

impl Copy for Fish

source§

impl Quoter for Fish

Auto Trait Implementations§

§

impl Freeze for Fish

§

impl RefUnwindSafe for Fish

§

impl Send for Fish

§

impl Sync for Fish

§

impl Unpin for Fish

§

impl UnwindSafe for Fish

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.