pub struct Character { /* private fields */ }Expand description
A colored character, has the same memory layout as u32.
§Examples
use color_char::Character;
let c = Character::default().with_char('Z').with_color(26);Implementations§
Source§impl Character
impl Character
Sourcepub fn new(char: char, color: u32) -> Self
pub fn new(char: char, color: u32) -> Self
Create a new colored character with the given character and color.
§Examples
use color_char::Character;Sourcepub fn get_char(&self) -> char
pub fn get_char(&self) -> char
Get the character for last 21 bits
§Examples
use color_char::Character;
let c = Character::from(0b000011010_000000000000001011010);
assert_eq!(c.get_char(), 'Z');
assert_eq!(c.get_color(), 26);Sourcepub fn set_char(&mut self, new: char)
pub fn set_char(&mut self, new: char)
Set the character on last 21 bits
§Examples
use color_char::Character;
let mut c = Character::default();
c.set_char('Z');
assert_eq!(c, 'Z');Sourcepub fn with_char(self, new: char) -> Self
pub fn with_char(self, new: char) -> Self
Build a new character with given char
§Examples
use color_char::Character;
let c = Character::default().with_char('Z');
assert_eq!(c, 'Z');Sourcepub fn get_color(&self) -> u32
pub fn get_color(&self) -> u32
Get the color id from first 11 bits
§Examples
use color_char::Character;
let c = Character::from(0b000011010_000000000000001011010);
assert_eq!(c.get_color(), 26);Sourcepub fn set_color(&mut self, new: u32)
pub fn set_color(&mut self, new: u32)
Set the color id on first 11 bits
§Examples
use color_char::Character;
let mut c = Character::default();
c.set_color(26);
assert_eq!(c.get_color(), 26);Sourcepub fn with_color(self, new: u32) -> Self
pub fn with_color(self, new: u32) -> Self
Build a new character with given color
§Examples
use color_char::Character;
let c = Character::default().with_color(26);
assert_eq!(c.get_color(), 26);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Character
impl<'de> Deserialize<'de> for Character
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Character
impl Ord for Character
Source§impl PartialOrd for Character
impl PartialOrd for Character
impl Copy for Character
impl Eq for Character
impl StructuralPartialEq for Character
Auto Trait Implementations§
impl Freeze for Character
impl RefUnwindSafe for Character
impl Send for Character
impl Sync for Character
impl Unpin for Character
impl UnwindSafe for Character
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more