[−][src]Struct abin::AnyStr
A utf-8 string backed by AnyBin
(Bin
or SBin
), see also Str
and SStr
.
Implementations
impl<TBin> AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
pub fn from_utf8(value: impl Into<TBin>) -> Result<Self, AnyStrUtf8Error<TBin>>
[src]
Converts the given value to a string.
The given value must be valid UTF-8. If the value is not valid UTF-8, this method returns an error containing the original binary.
See also: core::str::from_utf8
/ std::string::String::from_utf8
.
use abin::{NewBin, BinFactory, AnyStr, Bin}; let bin : Bin = NewBin::from_static(&[65u8, 66u8, 67u8]); let str : AnyStr<Bin> = AnyStr::from_utf8(bin).unwrap(); assert_eq!("ABC", str.as_str());
pub unsafe fn from_utf8_unchecked(value: TBin) -> Self
[src]
Creates a new string from given binary without checking whether the data in the given binary is valid UTF-8.
Safety
This function is unsafe because it does not check that the bytes passed to it are valid
UTF-8. If this constraint is violated, undefined behavior results, as AnyStr
assumes that it only contains valid UTF-8. See also core::str::from_utf8_unchecked
.
pub fn as_str(&self) -> &str
[src]
Returns &str
. It's a cheap operation. See AnyBin::as_slice
.
use abin::{Str, NewStr, StrFactory}; let string : Str = NewStr::from_static("Hello"); assert_eq!("Hello", string.as_str());
pub fn into_bin(self) -> TBin
[src]
Extracts the wrapped binary.
use abin::{Str, NewStr, StrFactory, AnyBin, Bin}; let string : Str = NewStr::from_static("ABC"); let bin : Bin = string.into_bin(); assert_eq!(&[65u8, 66u8, 67u8], bin.as_slice());
pub fn as_bin(&self) -> &TBin
[src]
Wrapped binary as reference.
use abin::{Str, NewStr, StrFactory, AnyBin, Bin}; let string : Str = NewStr::from_static("ABC"); let bin : &Bin = string.as_bin(); assert_eq!(&[65u8, 66u8, 67u8], bin.as_slice());
pub fn is_empty(&self) -> bool
[src]
true
if this string is empty (number of utf-8 bytes is 0). See also AnyBin::is_empty
.
use abin::{Str, NewStr, StrFactory}; let string : Str = NewStr::from_static(""); assert_eq!(true, string.is_empty());
pub fn len(&self) -> usize
[src]
The number of utf-8 bytes in this string. See also AnyBin::len
.
use abin::{Str, NewStr, StrFactory}; let string : Str = NewStr::from_static("Hello"); assert_eq!(5, string.len());
pub fn into_string(self) -> String
[src]
Converts this into a String
; depending on the type, this might allocate or not. See
also AnyBin::into_vec
.
use abin::{Str, NewStr, StrFactory}; let string : Str = NewStr::from_static("Hello"); let std_string : String = string.into_string(); assert_eq!("Hello", &std_string);
pub fn slice<TRange>(&self, range: TRange) -> Option<Self> where
TRange: RangeBounds<usize>,
[src]
TRange: RangeBounds<usize>,
Returns a slice of this string.
Returns None
if:
- range is ouf of bounds.
- or if the range does not lie on UTF-8 boundaries (see also
str::get
).
See also AnyBin::slice
.
use abin::{NewStr, StrFactory, Str}; let str : Str = NewStr::from_static("🗻∈🌏"); // works let slice1 : Option<Str> = str.slice(0..4); assert_eq!(Some(NewStr::from_static("🗻")), slice1); // indices not on UTF-8 sequence boundaries let slice2 : Option<Str> = str.slice(1..); assert!(slice2.is_none()); let slice3 : Option<Str> = str.slice(..8); assert!(slice3.is_none()); // out of bounds let slice4 : Option<Str> = str.slice(..42); assert!(slice4.is_none());
Trait Implementations
impl<TBin> AsRef<TBin> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> AsRef<str> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl BooToOwned<str, AnyStr<Bin>> for NewStr
[src]
fn convert_to_owned(borrowed: &str) -> Str
[src]
impl BooToOwned<str, AnyStr<SBin>> for NewSStr
[src]
fn convert_to_owned(borrowed: &str) -> SStr
[src]
impl<TBin> Borrow<str> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> Clone for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<TBin> Debug for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> Deref for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> Display for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> Eq for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<'a, TBin: AnyBin> From<AnyStr<TBin>> for StrSegment<'a, TBin>
[src]
impl<TBin> Hash for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<TBin> Into<String> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
See AnyStr::into_string
.
impl<TBin> IntoSync for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> IntoUnSync for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> IntoUnSyncView for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> Ord for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<TBin> PartialEq<AnyStr<TBin>> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> PartialEq<str> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
impl<TBin> PartialOrd<AnyStr<TBin>> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<TBin> PartialOrd<str> for AnyStr<TBin> where
TBin: AnyBin,
[src]
TBin: AnyBin,
Auto Trait Implementations
impl<TBin> RefUnwindSafe for AnyStr<TBin> where
TBin: RefUnwindSafe,
TBin: RefUnwindSafe,
impl<TBin> Send for AnyStr<TBin> where
TBin: Send,
TBin: Send,
impl<TBin> Sync for AnyStr<TBin> where
TBin: Sync,
TBin: Sync,
impl<TBin> Unpin for AnyStr<TBin> where
TBin: Unpin,
TBin: Unpin,
impl<TBin> UnwindSafe for AnyStr<TBin> where
TBin: UnwindSafe,
TBin: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,