[−][src]Struct const_format::AsciiStr
fmt
only.An ascii string slice.
You can also construct an AsciiStr
at compile-time with the ascii_str
macro,
erroring at compile if the constant isn't ascii.
Example
use const_format::wrapper_types::{AsciiStr, NotAsciiError}; use const_format::ascii_str; const HELLO: AsciiStr = unwrap_ascii(AsciiStr::new(b"hello")); const EURO: AsciiStr = unwrap_ascii(AsciiStr::new("foo €".as_bytes())); assert_eq!(HELLO.as_str(), "hello"); assert_eq!(EURO.as_str(), "<error>"); assert_eq!(AsciiStr::new("foo €".as_bytes()), Err(NotAsciiError{invalid_from: 4})); const fn unwrap_ascii(res: Result<AsciiStr<'_>, NotAsciiError>) -> AsciiStr<'_> { match res { Ok(x) => x, Err(_) => ascii_str!("<error>"), } }
Implementations
impl<'a> AsciiStr<'a>
[src]
pub const fn from_str(s: &'a str) -> Result<Self, NotAsciiError>
[src]
Constructs this AsciiStr from a possibly non-ascii str slice.
Returns a NonAsciiError
error on the first non-ascii byte.
Example
use const_format::wrapper_types::{AsciiStr, NotAsciiError}; let ok = AsciiStr::from_str("foo bar").unwrap(); assert_eq!(ok.as_str(), "foo bar"); assert_eq!(AsciiStr::from_str("foo bar ½"), Err(NotAsciiError{invalid_from: 8}));
pub const fn new(s: &'a [u8]) -> Result<Self, NotAsciiError>
[src]
Constructs this AsciiStr from a possibly non-ascii byte slice.
Returns a NonAsciiError
error on the first non-ascii byte.
Example
use const_format::wrapper_types::{AsciiStr, NotAsciiError}; let ok = AsciiStr::new(b"foo bar").unwrap(); assert_eq!(ok.as_str(), "foo bar"); assert_eq!(AsciiStr::new(b"foo bar \x80"), Err(NotAsciiError{invalid_from: 8}));
pub const fn empty() -> Self
[src]
Constructs an empty AsciiStr
Example
use const_format::AsciiStr; assert_eq!(AsciiStr::empty().as_str(), "");
pub const fn len(self) -> usize
[src]
Queries the length of the AsciiStr
Example
use const_format::{AsciiStr, ascii_str}; assert_eq!(AsciiStr::empty().len(), 0); assert_eq!(ascii_str!("hello").len(), 5);
pub const fn is_empty(self) -> bool
[src]
Queries whether this AsciiStr
is empty.
Example
use const_format::{AsciiStr, ascii_str}; assert_eq!(AsciiStr::empty().is_empty(), true); assert_eq!(ascii_str!("hello").is_empty(), false);
pub const fn as_bytes(self) -> &'a [u8]
[src]
Accessor for the wrapped ascii string.
Example
use const_format::{AsciiStr, ascii_str}; assert_eq!(AsciiStr::empty().as_bytes(), b""); assert_eq!(ascii_str!("hello").as_bytes(), b"hello");
pub fn as_str(self) -> &'a str
[src]
Accessor for the wrapped ascii string.
Example
use const_format::{AsciiStr, ascii_str}; assert_eq!(AsciiStr::empty().as_str(), ""); assert_eq!(ascii_str!("hello").as_str(), "hello");
impl AsciiStr<'_>
[src]
pub const fn const_display_fmt(
&self,
f: &mut Formatter<'_>
) -> Result<(), Error>
[src]
&self,
f: &mut Formatter<'_>
) -> Result<(), Error>
pub const fn const_debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
[src]
Trait Implementations
impl<'a> Clone for AsciiStr<'a>
[src]
pub fn clone(&self) -> AsciiStr<'a>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Copy for AsciiStr<'a>
[src]
impl<'a> Debug for AsciiStr<'a>
[src]
impl<'a> Eq for AsciiStr<'a>
[src]
impl FormatMarker for AsciiStr<'_>
[src]
type Kind = IsNotStdKind
What kind of type this is, this can be one of: Read more
type This = Self
The type after dereferencing,
implemented as type This = Self;
for all non-reference types Read more
impl<'a> Hash for AsciiStr<'a>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Ord for AsciiStr<'a>
[src]
pub fn cmp(&self, other: &AsciiStr<'a>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<'a> PartialEq<AsciiStr<'a>> for AsciiStr<'a>
[src]
pub fn eq(&self, other: &AsciiStr<'a>) -> bool
[src]
pub fn ne(&self, other: &AsciiStr<'a>) -> bool
[src]
impl<'a> PartialOrd<AsciiStr<'a>> for AsciiStr<'a>
[src]
pub fn partial_cmp(&self, other: &AsciiStr<'a>) -> Option<Ordering>
[src]
pub fn lt(&self, other: &AsciiStr<'a>) -> bool
[src]
pub fn le(&self, other: &AsciiStr<'a>) -> bool
[src]
pub fn gt(&self, other: &AsciiStr<'a>) -> bool
[src]
pub fn ge(&self, other: &AsciiStr<'a>) -> bool
[src]
impl<'a> StructuralEq for AsciiStr<'a>
[src]
impl<'a> StructuralPartialEq for AsciiStr<'a>
[src]
Auto Trait Implementations
impl<'a> Send for AsciiStr<'a>
[src]
impl<'a> Sync for AsciiStr<'a>
[src]
impl<'a> Unpin for AsciiStr<'a>
[src]
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,
pub 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, 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.
pub 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>,