Fish

Struct Fish 

Source
pub struct Fish;
Expand description

Quote byte strings for use with fish.

§⚠️ Warning

Prior to version 3.6.2, fish did not correctly handle some Unicode code points encoded as UTF-8. From the version 3.6.2 release notes:

fish uses certain Unicode non-characters internally for marking wildcards and expansions. It incorrectly allowed these markers to be read on command substitution output, rather than transforming them into a safe internal representation.

At present this crate has no workaround for this issue. Please use fish 3.6.2 or later.

§Notes

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_vec<'a, S: 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_vec for a variant that extends an existing Vec instead of allocating a new one.

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

pub fn quote_into_vec<'a, S: Into<Quotable<'a>>>(s: S, sout: &mut Vec<u8>)

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

See quote_vec for more details.

§Examples
let mut buf = Vec::with_capacity(128);
Fish::quote_into_vec("foobar", &mut buf);
buf.push(b' ');  // Add a space.
Fish::quote_into_vec("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 duplicate 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 QuoteInto<BString> for Fish

Source§

fn quote_into<'q, S: Into<Quotable<'q>>>(s: S, out: &mut BString)

Quote/escape a string of bytes into an existing container.
Source§

impl QuoteInto<OsString> for Fish

Source§

fn quote_into<'q, S: Into<Quotable<'q>>>(s: S, out: &mut OsString)

Quote/escape a string of bytes into an existing container.
Source§

impl QuoteInto<String> for Fish

Source§

fn quote_into<'q, S: Into<Quotable<'q>>>(s: S, out: &mut String)

Quote/escape a string of bytes into an existing container.
Source§

impl QuoteInto<Vec<u8>> for Fish

Source§

fn quote_into<'q, S: Into<Quotable<'q>>>(s: S, out: &mut Vec<u8>)

Quote/escape a string of bytes into an existing container.
Source§

impl Copy 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§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, OUT> Quote<OUT> for T
where T: QuoteInto<OUT>, OUT: Default,

Source§

fn quote<'q, S: Into<Quotable<'q>>>(s: S) -> OUT

Quote/escape a string of bytes into a new container.
Source§

impl<T> QuoteExt for T
where T: ?Sized,

Source§

fn push_quoted<'q, Q, S>(&mut self, _q: Q, s: S)
where Q: QuoteInto<T>, S: Into<Quotable<'q>>,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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.