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:
- you would have many unsafe from str conversions/“unnecessary” checks with a strict AsciiStr
- 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
impl SoftAsciiStr
pub fn from_unchecked(s: &str) -> &SoftAsciiStr
pub fn from_str_unchecked(s: &str) -> &SoftAsciiStr
pub fn from_unchecked_mut(s: &mut str) -> &mut SoftAsciiStr
pub fn from_str(source: &str) -> Result<&Self, FromSourceError<&str>>
Sourcepub fn revalidate_soft_constraint(&self) -> Result<&Self, FromSourceError<&str>>
pub fn revalidate_soft_constraint(&self) -> Result<&Self, FromSourceError<&str>>
reruns checks if the “is us-ascii” soft constraint is still valid
pub fn as_str(&self) -> &str
pub fn into_soft_ascii_string(self: Box<SoftAsciiStr>) -> SoftAsciiString
pub fn from_boxed_str(bs: Box<str>) -> Box<SoftAsciiStr>
pub fn into_boxed_str(self: Box<SoftAsciiStr>) -> Box<str>
pub fn lines(&self) -> SoftAsciiLines<'_> ⓘ
pub fn split_whitespace(&self) -> SoftAsciiSplitWhitespace<'_> ⓘ
pub fn char_indices(&self) -> SoftAsciiCharIndices<'_> ⓘ
pub fn chars(&self) -> SoftAsciiChars<'_> ⓘ
pub fn split_at(&self, mid: usize) -> (&SoftAsciiStr, &SoftAsciiStr)
pub unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &SoftAsciiStr
Sourcepub unsafe fn get_unchecked<I>(&self, index: I) -> &SoftAsciiStrwhere
I: TempSliceIndexHelper,
pub unsafe fn get_unchecked<I>(&self, index: I) -> &SoftAsciiStrwhere
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.
Sourcepub fn inner_str_mut(&mut self) -> &mut str
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.
pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err>where
F: FromStr,
Source§impl SoftAsciiStr
impl SoftAsciiStr
pub fn to_lowercase(&self) -> SoftAsciiString
Source§impl SoftAsciiStr
impl SoftAsciiStr
pub fn to_uppercase(&self) -> SoftAsciiString
Source§impl SoftAsciiStr
impl SoftAsciiStr
pub fn repeat(&self, n: usize) -> SoftAsciiString
Source§impl SoftAsciiStr
impl SoftAsciiStr
pub fn trim_right(&self) -> &SoftAsciiStr
pub fn trim_left(&self) -> &SoftAsciiStr
pub fn trim_end(&self) -> &SoftAsciiStr
pub fn trim_start(&self) -> &SoftAsciiStr
pub fn trim(&self) -> &SoftAsciiStr
Source§impl SoftAsciiStr
impl SoftAsciiStr
Trait Implementations§
Source§impl<'a> Add<&'a SoftAsciiStr> for SoftAsciiString
impl<'a> Add<&'a SoftAsciiStr> for SoftAsciiString
Source§type Output = SoftAsciiString
type Output = SoftAsciiString
+
operator.Source§fn add(self, other: &'a SoftAsciiStr) -> Self
fn add(self, other: &'a SoftAsciiStr) -> Self
+
operation. Read moreSource§impl<'a> AddAssign<&'a SoftAsciiStr> for SoftAsciiString
impl<'a> AddAssign<&'a SoftAsciiStr> for SoftAsciiString
Source§fn add_assign(&mut self, other: &'a SoftAsciiStr)
fn add_assign(&mut self, other: &'a SoftAsciiStr)
+=
operation. Read moreSource§impl AsRef<[u8]> for SoftAsciiStr
impl AsRef<[u8]> for SoftAsciiStr
Source§impl AsRef<OsStr> for SoftAsciiStr
impl AsRef<OsStr> for SoftAsciiStr
Source§impl AsRef<Path> for SoftAsciiStr
impl AsRef<Path> for SoftAsciiStr
Source§impl AsRef<SoftAsciiStr> for SoftAsciiStr
impl AsRef<SoftAsciiStr> for SoftAsciiStr
Source§impl AsRef<SoftAsciiStr> for SoftAsciiString
impl AsRef<SoftAsciiStr> for SoftAsciiString
Source§fn as_ref(&self) -> &SoftAsciiStr
fn as_ref(&self) -> &SoftAsciiStr
Source§impl AsRef<str> for SoftAsciiStr
impl AsRef<str> for SoftAsciiStr
Source§impl Borrow<SoftAsciiStr> for SoftAsciiString
impl Borrow<SoftAsciiStr> for SoftAsciiString
Source§fn borrow(&self) -> &SoftAsciiStr
fn borrow(&self) -> &SoftAsciiStr
Source§impl Debug for SoftAsciiStr
impl Debug for SoftAsciiStr
Source§impl<'a> Default for &'a SoftAsciiStr
impl<'a> Default for &'a SoftAsciiStr
Source§fn default() -> &'a SoftAsciiStr
fn default() -> &'a SoftAsciiStr
Source§impl Display for SoftAsciiStr
impl Display for SoftAsciiStr
Source§impl<'a> Extend<&'a SoftAsciiStr> for SoftAsciiString
impl<'a> Extend<&'a SoftAsciiStr> for SoftAsciiString
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a SoftAsciiStr>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a SoftAsciiStr>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> From<&'a SoftAsciiStr> for SoftAsciiCharIndices<'a>
impl<'a> From<&'a SoftAsciiStr> for SoftAsciiCharIndices<'a>
Source§fn from(s: &'a SoftAsciiStr) -> SoftAsciiCharIndices<'a> ⓘ
fn from(s: &'a SoftAsciiStr) -> SoftAsciiCharIndices<'a> ⓘ
Source§impl<'a> From<&'a SoftAsciiStr> for SoftAsciiChars<'a>
impl<'a> From<&'a SoftAsciiStr> for SoftAsciiChars<'a>
Source§fn from(s: &'a SoftAsciiStr) -> SoftAsciiChars<'a> ⓘ
fn from(s: &'a SoftAsciiStr) -> SoftAsciiChars<'a> ⓘ
Source§impl<'a> From<&'a SoftAsciiStr> for SoftAsciiLines<'a>
impl<'a> From<&'a SoftAsciiStr> for SoftAsciiLines<'a>
Source§fn from(s: &'a SoftAsciiStr) -> SoftAsciiLines<'a> ⓘ
fn from(s: &'a SoftAsciiStr) -> SoftAsciiLines<'a> ⓘ
Source§impl<'a> From<&'a SoftAsciiStr> for SoftAsciiSplitWhitespace<'a>
impl<'a> From<&'a SoftAsciiStr> for SoftAsciiSplitWhitespace<'a>
Source§fn from(s: &'a SoftAsciiStr) -> SoftAsciiSplitWhitespace<'a> ⓘ
fn from(s: &'a SoftAsciiStr) -> SoftAsciiSplitWhitespace<'a> ⓘ
Source§impl<'a> From<&'a SoftAsciiStr> for SoftAsciiString
impl<'a> From<&'a SoftAsciiStr> for SoftAsciiString
Source§fn from(s: &'a SoftAsciiStr) -> Self
fn from(s: &'a SoftAsciiStr) -> Self
Source§impl<'a> FromIterator<&'a SoftAsciiStr> for SoftAsciiString
impl<'a> FromIterator<&'a SoftAsciiStr> for SoftAsciiString
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = &'a SoftAsciiStr>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = &'a SoftAsciiStr>,
Source§impl Hash for SoftAsciiStr
impl Hash for SoftAsciiStr
Source§impl Index<RangeFull> for SoftAsciiStr
impl Index<RangeFull> for SoftAsciiStr
Source§impl Ord for SoftAsciiStr
impl Ord for SoftAsciiStr
Source§impl<'a, 'b> PartialEq<&'b SoftAsciiStr> for Cow<'a, SoftAsciiStr>
impl<'a, 'b> PartialEq<&'b SoftAsciiStr> for Cow<'a, SoftAsciiStr>
Source§impl<'a> PartialEq<&'a SoftAsciiStr> for OsString
impl<'a> PartialEq<&'a SoftAsciiStr> for OsString
Source§impl<'a> PartialEq<&'a SoftAsciiStr> for SoftAsciiString
impl<'a> PartialEq<&'a SoftAsciiStr> for SoftAsciiString
Source§impl<'a> PartialEq<&'a SoftAsciiStr> for String
impl<'a> PartialEq<&'a SoftAsciiStr> for String
Source§impl<'a, 'b> PartialEq<Cow<'a, SoftAsciiStr>> for &'a SoftAsciiStr
impl<'a, 'b> PartialEq<Cow<'a, SoftAsciiStr>> for &'a SoftAsciiStr
Source§impl<'a> PartialEq<Cow<'a, SoftAsciiStr>> for SoftAsciiStr
impl<'a> PartialEq<Cow<'a, SoftAsciiStr>> for SoftAsciiStr
Source§impl PartialEq<OsStr> for SoftAsciiStr
impl PartialEq<OsStr> for SoftAsciiStr
Source§impl<'a> PartialEq<OsString> for &'a SoftAsciiStr
impl<'a> PartialEq<OsString> for &'a SoftAsciiStr
Source§impl PartialEq<OsString> for SoftAsciiStr
impl PartialEq<OsString> for SoftAsciiStr
Source§impl<'a> PartialEq<SoftAsciiStr> for Cow<'a, SoftAsciiStr>
impl<'a> PartialEq<SoftAsciiStr> for Cow<'a, SoftAsciiStr>
Source§impl PartialEq<SoftAsciiStr> for OsStr
impl PartialEq<SoftAsciiStr> for OsStr
Source§impl PartialEq<SoftAsciiStr> for OsString
impl PartialEq<SoftAsciiStr> for OsString
Source§impl PartialEq<SoftAsciiStr> for String
impl PartialEq<SoftAsciiStr> for String
Source§impl<'a> PartialEq<SoftAsciiStr> for str
impl<'a> PartialEq<SoftAsciiStr> for str
Source§impl<'a> PartialEq<SoftAsciiString> for &'a SoftAsciiStr
impl<'a> PartialEq<SoftAsciiString> for &'a SoftAsciiStr
Source§impl PartialEq<SoftAsciiString> for SoftAsciiStr
impl PartialEq<SoftAsciiString> for SoftAsciiStr
Source§impl<'a> PartialEq<String> for &'a SoftAsciiStr
impl<'a> PartialEq<String> for &'a SoftAsciiStr
Source§impl PartialEq<String> for SoftAsciiStr
impl PartialEq<String> for SoftAsciiStr
Source§impl PartialEq<str> for SoftAsciiStr
impl PartialEq<str> for SoftAsciiStr
Source§impl PartialEq for SoftAsciiStr
impl PartialEq for SoftAsciiStr
Source§impl PartialOrd for SoftAsciiStr
impl PartialOrd for SoftAsciiStr
Source§impl ToOwned for SoftAsciiStr
impl ToOwned for SoftAsciiStr
Source§type Owned = SoftAsciiString
type Owned = SoftAsciiString
Source§fn to_owned(&self) -> SoftAsciiString
fn to_owned(&self) -> SoftAsciiString
1.63.0 · Source§fn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
Source§impl ToSocketAddrs for SoftAsciiStr
impl ToSocketAddrs for SoftAsciiStr
Source§type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Source§fn to_socket_addrs(&self) -> Result<IntoIter<SocketAddr>>
fn to_socket_addrs(&self) -> Result<IntoIter<SocketAddr>>
SocketAddr
s. Read more