Struct _SoftAsciiStr

Source
pub struct _SoftAsciiStr(/* private fields */);
Expand description

A str wrapper adding a “is us-ascii” soft constraint.

This means that it should be ascii but is not guaranteed to be ascii. Which means non ascii chars are not a safety issue just a potential bug.

This is useful for situations where:

  1. you would have many unsafe from str conversions/“unnecessary” checks with a strict AsciiStr
  2. you rarely have to strictly rely on the value being ascii

§Note

Some functions which should be implemented directly on SoftAsciiStr like e.g. trim_matches are only provided through .as_str(). This is because the Pattern API and SliceIndex API is unstable i.e. can only be implemented in unstable for now. Once it gets stabilized (rust #27721/#35729) implementations can be added

Implementations§

Source§

impl SoftAsciiStr

Source

pub fn from_unchecked(s: &str) -> &SoftAsciiStr

Source

pub fn from_str_unchecked(s: &str) -> &SoftAsciiStr

👎Deprecated since 1.0.0: use from_unchecked
Source

pub fn from_unchecked_mut(s: &mut str) -> &mut SoftAsciiStr

Source

pub fn from_str(source: &str) -> Result<&SoftAsciiStr, FromSourceError<&str>>

Source

pub fn revalidate_soft_constraint( &self, ) -> Result<&SoftAsciiStr, FromSourceError<&str>>

reruns checks if the “is us-ascii” soft constraint is still valid

Source

pub fn as_str(&self) -> &str

Source

pub fn into_soft_ascii_string(self: Box<SoftAsciiStr>) -> SoftAsciiString

Source

pub fn from_boxed_str(bs: Box<str>) -> Box<SoftAsciiStr>

Source

pub fn into_boxed_str(self: Box<SoftAsciiStr>) -> Box<str>

Source

pub fn lines(&self) -> SoftAsciiLines<'_>

Source

pub fn split_whitespace(&self) -> SoftAsciiSplitWhitespace<'_>

Source

pub fn char_indices(&self) -> SoftAsciiCharIndices<'_>

Source

pub fn chars(&self) -> SoftAsciiChars<'_>

Source

pub fn split_at(&self, mid: usize) -> (&SoftAsciiStr, &SoftAsciiStr)

Source

pub unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &SoftAsciiStr

👎Deprecated since 1.1.0: deprecated in std
Source

pub unsafe fn get_unchecked<I>(&self, index: I) -> &SoftAsciiStr
where I: TempSliceIndexHelper,

Proxy of std::str::get_unchecked.

Currently limited to the various range types:

  • Range<usize>
  • RangeInclusive<usize>
  • RangeFrom<usize>
  • RangeTo<usize>
  • RangeToInclusive<usize>
  • RangeFull

Once all methods on SliceIndex are stable this can be implemented using SliceIndex<SoftAsciiStr> bounds.

Source

pub fn inner_str_mut(&mut self) -> &mut str

returns a mutable str reference to the inner buffer

§Soft Constraint

be aware that it is very easy to introduce bugs when directly editing a SoftAsciiStr as an str. Still compared to a AsciiStr implementation this won’t introduce unsafety, just possible brakeage of the soft constraint that the data should be ascii.

Source

pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err>
where F: FromStr,

Source§

impl SoftAsciiStr

Source§

impl SoftAsciiStr

Source§

impl SoftAsciiStr

Source

pub fn repeat(&self, n: usize) -> SoftAsciiString

Source§

impl SoftAsciiStr

Source

pub fn trim_right(&self) -> &SoftAsciiStr

👎Deprecated since 1.1.0: deprecated in std
Source

pub fn trim_left(&self) -> &SoftAsciiStr

👎Deprecated since 1.1.0: deprecated in std
Source

pub fn trim_end(&self) -> &SoftAsciiStr

Source

pub fn trim_start(&self) -> &SoftAsciiStr

Source

pub fn trim(&self) -> &SoftAsciiStr

Source§

impl SoftAsciiStr

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_char_boundary(&self, index: usize) -> bool

Source

pub fn as_ptr(&self) -> *const u8

Source

pub fn encode_utf16(&self) -> EncodeUtf16<'_>

Source

pub fn is_ascii(&self) -> bool

Source

pub fn as_bytes(&self) -> &[u8]

Trait Implementations§

Source§

impl AsRef<[u8]> for SoftAsciiStr

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<OsStr> for SoftAsciiStr

Source§

fn as_ref(&self) -> &OsStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Path> for SoftAsciiStr

Source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<SoftAsciiStr> for SoftAsciiStr

Source§

fn as_ref(&self) -> &SoftAsciiStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for SoftAsciiStr

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for SoftAsciiStr

Source§

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

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

impl<'a> Default for &'a SoftAsciiStr

Source§

fn default() -> &'a SoftAsciiStr

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

impl Display for SoftAsciiStr

Source§

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

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

impl Hash for SoftAsciiStr

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
Source§

impl Index<Range<usize>> for SoftAsciiStr

Source§

type Output = SoftAsciiStr

The returned type after indexing.
Source§

fn index( &self, index: Range<usize>, ) -> &<SoftAsciiStr as Index<Range<usize>>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for SoftAsciiStr

Source§

type Output = SoftAsciiStr

The returned type after indexing.
Source§

fn index( &self, index: RangeFrom<usize>, ) -> &<SoftAsciiStr as Index<RangeFrom<usize>>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for SoftAsciiStr

Source§

type Output = SoftAsciiStr

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &<SoftAsciiStr as Index<RangeFull>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for SoftAsciiStr

Source§

type Output = SoftAsciiStr

The returned type after indexing.
Source§

fn index( &self, index: RangeTo<usize>, ) -> &<SoftAsciiStr as Index<RangeTo<usize>>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Ord for SoftAsciiStr

Source§

fn cmp(&self, other: &SoftAsciiStr) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl<'a, 'b> PartialEq<Cow<'a, SoftAsciiStr>> for &'a SoftAsciiStr

Source§

fn eq(&self, other: &Cow<'a, SoftAsciiStr>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Cow<'a, SoftAsciiStr>> for SoftAsciiStr

Source§

fn eq(&self, other: &Cow<'a, SoftAsciiStr>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Cow<'a, str>> for SoftAsciiStr

Source§

fn eq(&self, other: &Cow<'a, str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b> PartialEq<Cow<'b, str>> for &'a SoftAsciiStr

Source§

fn eq(&self, other: &Cow<'b, str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<OsStr> for SoftAsciiStr

Source§

fn eq(&self, other: &OsStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<OsString> for &'a SoftAsciiStr

Source§

fn eq(&self, other: &OsString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<OsString> for SoftAsciiStr

Source§

fn eq(&self, other: &OsString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<SoftAsciiStr> for HeaderName

Source§

fn eq(&self, other: &SoftAsciiStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<SoftAsciiStr> for OsStr

Source§

fn eq(&self, other: &SoftAsciiStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<SoftAsciiStr> for str

Source§

fn eq(&self, other: &SoftAsciiStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<SoftAsciiString> for &'a SoftAsciiStr

Source§

fn eq(&self, other: &SoftAsciiString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<SoftAsciiString> for SoftAsciiStr

Source§

fn eq(&self, other: &SoftAsciiString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<String> for &'a SoftAsciiStr

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for SoftAsciiStr

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for SoftAsciiStr

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for SoftAsciiStr

Source§

fn eq(&self, other: &SoftAsciiStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SoftAsciiStr

Source§

fn partial_cmp(&self, other: &SoftAsciiStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToOwned for SoftAsciiStr

Source§

type Owned = SoftAsciiString

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> SoftAsciiString

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl ToSocketAddrs for SoftAsciiStr

Source§

type Iter = IntoIter<SocketAddr>

Returned iterator over socket addresses which this type may correspond to.
Source§

fn to_socket_addrs(&self) -> Result<IntoIter<SocketAddr>, Error>

Converts this object to an iterator of resolved SocketAddrs. Read more
Source§

impl Eq for SoftAsciiStr

Source§

impl StructuralPartialEq for SoftAsciiStr

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more