pub struct AsciiChar { /* private fields */ }
Expand description

A struct representing an ASCII character.

This struct is used to represent an ASCII character in terms of a Byte value. This struct allows for interrogating the character in terms of its binary, decimal, and hexadecimal values, as well as its character code, character description, and character value.

Examples

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.binary_value(), Byte::from(97));
assert_eq!(ascii_char.decimal_value(), 97);
assert_eq!(ascii_char.hexadecimal_value(), "0x61");
assert_eq!(ascii_char.character_code(), "LCA");
assert_eq!(ascii_char.character_description(), "Lowercase letter a");
assert_eq!(ascii_char.character_value(), "a");

ASCII Character Types

The following ASCII character types are available:

  • Control characters
  • Printable characters
    • Whitespace characters
    • Digit characters
    • Letter characters
      • Uppercase characters
      • Lowercase characters
    • Symbol characters

ASCII Character Type Examples

Control Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(0), "NUL", "Null character", "\0");

assert_eq!(ascii_char.is_control(), true);

Printable Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.is_printable(), true);

Whitespace Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(9), "CTAB", "Horizontal tab", "\t");

assert_eq!(ascii_char.is_whitespace(), true);

Digit Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(49), "DIG1", "Digit one", "1");

assert_eq!(ascii_char.is_digit(), true);

Letter Characters

Uppercase Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter a", "A");

assert_eq!(ascii_char.is_uppercase(), true);
assert_eq!(ascii_char.is_lowercase(), false);
assert_eq!(ascii_char.is_letter(), true);

Lowercase Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.is_lowercase(), true);
assert_eq!(ascii_char.is_uppercase(), false);
assert_eq!(ascii_char.is_letter(), true);

Symbol Characters

use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(64), "AT", "At Symbol", "@");

assert_eq!(ascii_char.is_symbol(), true);

References

Implementations§

source§

impl AsciiChar

source

pub fn new( byte: Byte, character_code: &str, character_description: &str, character_value: &str ) -> Self

Create a new AsciiChar instance.

This function creates a new AsciiChar instance from the given Byte value, character code, character description, and character value.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.binary_value(), Byte::from(97));
assert_eq!(ascii_char.decimal_value(), 97);
assert_eq!(ascii_char.hexadecimal_value(), "0x61");
assert_eq!(ascii_char.character_code(), "LCA");
assert_eq!(ascii_char.character_description(), "Lowercase letter a");
source

pub fn is_control(&self) -> bool

Returns true if the AsciiChar instance is a control character.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(0), "NUL", "Null character", "\0");

assert_eq!(ascii_char.is_control(), true);
Control Characters
  • NUL (Null character)
  • SOH (Start of heading)
  • STX (Start of text)
  • ETX (End of text)
  • EOT (End of transmission)
  • ENQ (Enquiry)
  • ACK (Acknowledgement)
  • BEL (Bell)
  • BS (Backspace)
  • HT (Horizontal tab)
  • LF (Line feed)
  • VT (Vertical tab)
  • FF (Form feed)
  • CR (Carriage return)
  • SO (Shift out)
  • SI (Shift in)
  • DLE (Data link escape)
  • DC1 (Device control 1)
  • DC2 (Device control 2)
  • DC3 (Device control 3)
  • DC4 (Device control 4)
  • NAK (Negative acknowledgement)
  • SYN (Synchronous idle)
  • ETB (End of transmission block)
  • CAN (Cancel)
  • EM (End of medium)
  • SUB (Substitute)
  • ESC (Escape)
  • FS (File separator)
  • GS (Group separator)
  • RS (Record separator)
  • US (Unit separator)
  • DEL (Delete)
References
source

pub fn is_printable(&self) -> bool

Returns true if the AsciiChar instance is a printable character.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let lca: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
let uca: AsciiChar =
    AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter a", "A");
let symat: AsciiChar =
    AsciiChar::new(Byte::from(64), "SYMAT", "Symbol At", "@");
let dig1: AsciiChar =
    AsciiChar::new(Byte::from(49), "DIG1", "Digit one", "1");
let sp: AsciiChar = AsciiChar::new(Byte::from(32), "SP", "Space", " ");

assert_eq!(lca.is_printable(), true);
assert_eq!(uca.is_printable(), true);
assert_eq!(symat.is_printable(), true);
assert_eq!(dig1.is_printable(), true);
assert_eq!(sp.is_printable(), true);
Printable Characters
References
source

pub fn is_whitespace(&self) -> bool

Returns true if the AsciiChar instance is a whitespace character.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(9), "CTAB", "Horizontal tab", "\t");

assert_eq!(ascii_char.is_whitespace(), true);
Whitespace Characters
  • SP (Space)
  • HT (Horizontal tab)
  • LF (Line feed)
  • VT (Vertical tab)
  • FF (Form feed)
  • CR (Carriage return)
References
source

pub fn is_digit(&self) -> bool

Returns true if the AsciiChar instance is a digit character.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(49), "DIG1", "Digit one", "1");

assert_eq!(ascii_char.is_digit(), true);
Digit Characters
  • All digit characters from 0 to 9
References
source

pub fn is_letter(&self) -> bool

Returns true if the AsciiChar instance is a letter character.

Examples
Lowercase Letters
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.is_letter(), true);
Uppercase Letters
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let lca: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
let uca: AsciiChar =
    AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter a", "A");

assert_eq!(lca.is_letter(), true);
assert_eq!(uca.is_letter(), true);
Letter Characters
References
source

pub fn is_uppercase(&self) -> bool

Returns true if the AsciiChar instance is an uppercase letter

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter A", "A");

assert_eq!(ascii_char.is_uppercase(), true);
Uppercase Letters
  • All uppercase letters from A to Z
References
source

pub fn is_lowercase(&self) -> bool

Returns true if the AsciiChar instance is a lowercase letter

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.is_lowercase(), true);
Lowercase Letters
  • All lowercase letters from a to z
References
source

pub fn is_symbol(&self) -> bool

Returns true if the AsciiChar instance is a symbol character.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(64), "SYMAT", "Symbol at", "@");

assert_eq!(ascii_char.is_symbol(), true);
Symbol Characters
  • All symbol characters from ! to /
  • All symbol characters from : to @
  • All symbol characters from [ to `
  • All symbol characters from { to ~
References
source

pub const fn binary_value(&self) -> Byte

Returns the AsciiChar instance’s binary value.

This function returns the AsciiChar instance’s binary value as a Byte.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.binary_value(), Byte::from(97));
source

pub fn decimal_value(&self) -> u8

Returns the AsciiChar instance’s decimal value.

This function returns the AsciiChar instance’s decimal value as a u8.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.decimal_value(), 97);
source

pub fn hexadecimal_value(&self) -> String

Returns the AsciiChar instance’s hexadecimal value.

This function returns the AsciiChar instance’s hexadecimal value as a String.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.hexadecimal_value(), "0x61");
source

pub fn character_code(&self) -> String

Returns the AsciiChar instance’s character code.

This function returns the AsciiChar instance’s character code as a String.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.character_code(), "LCA");
source

pub fn character_description(&self) -> String

Returns the AsciiChar instance’s character description.

This function returns the AsciiChar instance’s character description as a String.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.character_description(), "Lowercase letter a");
source

pub fn character_value(&self) -> String

Returns the AsciiChar instance’s character value.

This function returns the AsciiChar instance’s character value as a String.

Examples
use brainfoamkit_lib::{
    AsciiChar,
    Byte,
};

let ascii_char: AsciiChar =
    AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");

assert_eq!(ascii_char.character_value(), "a");

Trait Implementations§

source§

impl Clone for AsciiChar

source§

fn clone(&self) -> AsciiChar

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AsciiChar

source§

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

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

impl PartialEq for AsciiChar

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for AsciiChar

source§

impl StructuralEq for AsciiChar

source§

impl StructuralPartialEq for AsciiChar

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.