[−][src]Enum adafruit_alphanum4::AsciiChar
An ASCII character. It wraps a u8
, with the highest bit always zero.
Variants
'\0'
'\a'
is not recognized by Rust.
'\b'
is not recognized by Rust.
'\t'
'\n'
'\v'
is not recognized by Rust.
'\f'
is not recognized by Rust.
'\r'
Device control 2
Device control 3, Often XOFF
Device control 4
'\e'
is not recognized by Rust.
' '
'!'
'"'
'#'
'$'
'%'
'&'
'\''
'('
')'
'*'
'+'
','
'-'
'.'
'/'
'0'
'1'
'2'
'3'
'4'
'5'
'6'
'7'
'8'
'9'
':'
';'
'<'
'='
'>'
'?'
'@'
'A'
'B'
'C'
'D'
'E'
'F'
'G'
'H'
'I'
'J'
'K'
'L'
'M'
'N'
'O'
'P'
'Q'
'R'
'S'
'T'
'U'
'V'
'W'
'X'
'Y'
'Z'
'['
'\'
']'
'_'
'_'
'
'`
'a'
'b'
'c'
'd'
'e'
'f'
'g'
'h'
'i'
'j'
'k'
'l'
'm'
'n'
'o'
'p'
'q'
'r'
's'
't'
'u'
'v'
'w'
'x'
'y'
'z'
'{'
'|'
'}'
'~'
Methods
impl AsciiChar
[src]
pub fn from_ascii<C>(ch: C) -> Result<AsciiChar, ToAsciiCharError> where
C: ToAsciiChar,
[src]
C: ToAsciiChar,
Constructs an ASCII character from a u8
, char
or other character type.
Failure
Returns Err(())
if the character can't be ASCII encoded.
Example
let a = AsciiChar::from_ascii('g').unwrap(); assert_eq!(a.as_char(), 'g');
pub const fn new(ch: char) -> AsciiChar
[src]
Create an AsciiChar
from a char
, panicking if it's not ASCII.
This function is intended for creating AsciiChar
values from
hardcoded known-good character literals such as 'K'
, '-'
or '\0'
,
and for use in const
contexts.
Use from_ascii()
instead when you're not
certain the character is ASCII.
Examples
assert_eq!(AsciiChar::new('@'), AsciiChar::At); assert_eq!(AsciiChar::new('C').as_char(), 'C');
In a constant:
const SPLIT_ON: AsciiChar = AsciiChar::new(',');
This will not compile:
const BAD: AsciiChar = AsciiChar::new('Ø');
Panics
This function will panic if passed a non-ASCII character.
The panic message might not be the most descriptive due to the
current limitations of const fn
.
pub unsafe fn from_ascii_unchecked(ch: u8) -> AsciiChar
[src]
Constructs an ASCII character from a u8
, char
or other character
type without any checks.
Safety
This function is very unsafe as it can create invalid enum
discriminants, which instantly creates undefined behavior.
(let _ = AsciiChar::from_ascii_unchecked(200);
alone is UB).
The undefined behavior is not just theoretical either:
For example, [0; 128][AsciiChar::from_ascii_unchecked(255) as u8 as usize] = 0
might not panic, creating a buffer overflow,
and Some(AsciiChar::from_ascii_unchecked(128))
might be None
.
pub const fn as_byte(self) -> u8
[src]
Converts an ASCII character into a u8
.
pub const fn as_char(self) -> char
[src]
Converts an ASCII character into a char
.
pub const fn is_alphabetic(self) -> bool
[src]
Check if the character is a letter (a-z, A-Z)
pub const fn is_ascii_alphabetic(&self) -> bool
[src]
Check if the character is a letter (a-z, A-Z).
This method is identical to is_alphabetic()
pub fn is_digit(self, radix: u32) -> bool
[src]
Check if the character is a digit in the given radix.
If the radix is always 10 or 16,
is_ascii_digit()
and
is_ascii_hexdigit()
will be faster.
Panics
Radixes greater than 36 are not supported and will result in a panic.
pub const fn is_ascii_digit(&self) -> bool
[src]
Check if the character is a number (0-9)
Examples
assert_eq!(AsciiChar::new('0').is_ascii_digit(), true); assert_eq!(AsciiChar::new('9').is_ascii_digit(), true); assert_eq!(AsciiChar::new('a').is_ascii_digit(), false); assert_eq!(AsciiChar::new('A').is_ascii_digit(), false); assert_eq!(AsciiChar::new('/').is_ascii_digit(), false);
pub const fn is_alphanumeric(self) -> bool
[src]
Check if the character is a letter or number
pub const fn is_ascii_alphanumeric(&self) -> bool
[src]
Check if the character is a letter or number
This method is identical to is_alphanumeric()
pub const fn is_ascii_blank(&self) -> bool
[src]
Check if the character is a space or horizontal tab
Examples
assert!(AsciiChar::Space.is_ascii_blank()); assert!(AsciiChar::Tab.is_ascii_blank()); assert!(!AsciiChar::VT.is_ascii_blank()); assert!(!AsciiChar::LineFeed.is_ascii_blank()); assert!(!AsciiChar::CarriageReturn.is_ascii_blank()); assert!(!AsciiChar::FF.is_ascii_blank());
pub const fn is_whitespace(self) -> bool
[src]
Check if the character one of ' ', '\t', '\n', '\r', '\0xb' (vertical tab) or '\0xc' (form feed).
pub const fn is_ascii_whitespace(&self) -> bool
[src]
Check if the character is a ' ', '\t', '\n', '\r' or '\0xc' (form feed).
This method is NOT identical to is_whitespace()
.
pub const fn is_ascii_control(&self) -> bool
[src]
Check if the character is a control character
Examples
assert_eq!(AsciiChar::new('\0').is_ascii_control(), true); assert_eq!(AsciiChar::new('n').is_ascii_control(), false); assert_eq!(AsciiChar::new(' ').is_ascii_control(), false); assert_eq!(AsciiChar::new('\n').is_ascii_control(), true); assert_eq!(AsciiChar::new('\t').is_ascii_control(), true); assert_eq!(AsciiChar::EOT.is_ascii_control(), true);
pub const fn is_ascii_graphic(&self) -> bool
[src]
Checks if the character is printable (except space)
Examples
assert_eq!(AsciiChar::new('n').is_ascii_graphic(), true); assert_eq!(AsciiChar::new(' ').is_ascii_graphic(), false); assert_eq!(AsciiChar::new('\n').is_ascii_graphic(), false);
pub const fn is_ascii_printable(&self) -> bool
[src]
Checks if the character is printable (including space)
Examples
assert_eq!(AsciiChar::new('n').is_ascii_printable(), true); assert_eq!(AsciiChar::new(' ').is_ascii_printable(), true); assert_eq!(AsciiChar::new('\n').is_ascii_printable(), false);
pub const fn is_lowercase(self) -> bool
[src]
Checks if the character is alphabetic and lowercase (a-z).
Examples
use ascii::AsciiChar; assert_eq!(AsciiChar::new('a').is_lowercase(), true); assert_eq!(AsciiChar::new('A').is_lowercase(), false); assert_eq!(AsciiChar::new('@').is_lowercase(), false);
pub const fn is_ascii_lowercase(&self) -> bool
[src]
Checks if the character is alphabetic and lowercase (a-z).
This method is identical to is_lowercase()
pub const fn is_uppercase(self) -> bool
[src]
Checks if the character is alphabetic and uppercase (A-Z).
Examples
assert_eq!(AsciiChar::new('A').is_uppercase(), true); assert_eq!(AsciiChar::new('a').is_uppercase(), false); assert_eq!(AsciiChar::new('@').is_uppercase(), false);
pub const fn is_ascii_uppercase(&self) -> bool
[src]
Checks if the character is alphabetic and uppercase (A-Z).
This method is identical to is_uppercase()
pub const fn is_ascii_punctuation(&self) -> bool
[src]
Checks if the character is punctuation
Examples
assert_eq!(AsciiChar::new('n').is_ascii_punctuation(), false); assert_eq!(AsciiChar::new(' ').is_ascii_punctuation(), false); assert_eq!(AsciiChar::new('_').is_ascii_punctuation(), true); assert_eq!(AsciiChar::new('~').is_ascii_punctuation(), true);
pub const fn is_ascii_hexdigit(&self) -> bool
[src]
Checks if the character is a valid hex digit
Examples
assert_eq!(AsciiChar::new('5').is_ascii_hexdigit(), true); assert_eq!(AsciiChar::new('a').is_ascii_hexdigit(), true); assert_eq!(AsciiChar::new('F').is_ascii_hexdigit(), true); assert_eq!(AsciiChar::new('G').is_ascii_hexdigit(), false); assert_eq!(AsciiChar::new(' ').is_ascii_hexdigit(), false);
pub fn as_printable_char(self) -> char
[src]
Unicode has printable versions of the ASCII control codes, like '␛'.
This function is identical with .as_char()
for all values .is_printable()
returns true for,
but replaces the control codes with those unicodes printable versions.
Examples
assert_eq!(AsciiChar::new('\0').as_printable_char(), '␀'); assert_eq!(AsciiChar::new('\n').as_printable_char(), '␊'); assert_eq!(AsciiChar::new(' ').as_printable_char(), ' '); assert_eq!(AsciiChar::new('p').as_printable_char(), 'p');
pub fn make_ascii_uppercase(&mut self)
[src]
Replaces letters a
to z
with A
to Z
pub fn make_ascii_lowercase(&mut self)
[src]
Replaces letters A
to Z
with a
to z
pub const fn to_ascii_uppercase(&self) -> AsciiChar
[src]
Maps letters a-z to A-Z and returns any other character unchanged.
Examples
assert_eq!(AsciiChar::new('u').to_ascii_uppercase().as_char(), 'U'); assert_eq!(AsciiChar::new('U').to_ascii_uppercase().as_char(), 'U'); assert_eq!(AsciiChar::new('2').to_ascii_uppercase().as_char(), '2'); assert_eq!(AsciiChar::new('=').to_ascii_uppercase().as_char(), '='); assert_eq!(AsciiChar::new('[').to_ascii_uppercase().as_char(), '[');
pub const fn to_ascii_lowercase(&self) -> AsciiChar
[src]
Maps letters A-Z to a-z and returns any other character unchanged.
Examples
assert_eq!(AsciiChar::new('U').to_ascii_lowercase().as_char(), 'u'); assert_eq!(AsciiChar::new('u').to_ascii_lowercase().as_char(), 'u'); assert_eq!(AsciiChar::new('2').to_ascii_lowercase().as_char(), '2'); assert_eq!(AsciiChar::new('^').to_ascii_lowercase().as_char(), '^'); assert_eq!(AsciiChar::new('\x7f').to_ascii_lowercase().as_char(), '\x7f');
pub const fn eq_ignore_ascii_case(&self, other: &AsciiChar) -> bool
[src]
Compares two characters case-insensitively.
Trait Implementations
impl StructuralPartialEq for AsciiChar
[src]
impl StructuralEq for AsciiChar
[src]
impl AsRef<AsciiStr> for AsciiChar
[src]
impl Debug for AsciiChar
[src]
impl PartialOrd<u8> for AsciiChar
[src]
fn partial_cmp(&self, rhs: &u8) -> 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 PartialOrd<AsciiChar> for AsciiChar
[src]
fn partial_cmp(&self, other: &AsciiChar) -> 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 PartialOrd<char> for AsciiChar
[src]
fn partial_cmp(&self, rhs: &char) -> 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 Clone for AsciiChar
[src]
fn clone(&self) -> AsciiChar
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for AsciiChar
[src]
impl Hash for AsciiChar
[src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for AsciiChar
[src]
fn cmp(&self, other: &AsciiChar) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl ToAsciiChar for AsciiChar
[src]
fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError>
[src]
unsafe fn to_ascii_char_unchecked(self) -> AsciiChar
[src]
impl Eq for AsciiChar
[src]
impl PartialEq<u8> for AsciiChar
[src]
impl PartialEq<AsciiChar> for AsciiChar
[src]
impl PartialEq<char> for AsciiChar
[src]
impl Display for AsciiChar
[src]
impl Copy for AsciiChar
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,