Skip to content

Update for Show/String reform #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,27 @@ impl Ascii {
}
}

impl fmt::String for Ascii {
impl fmt::Display for Ascii {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&(self.chr as char), f)
fmt::Display::fmt(&(self.chr as char), f)
}
}

impl fmt::String for Vec<Ascii> {
impl fmt::Display for Vec<Ascii> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&self[], f)
fmt::Display::fmt(&self[], f)
}
}

impl fmt::String for [Ascii] {
impl fmt::Display for [Ascii] {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(self.as_str(), f)
fmt::Display::fmt(self.as_str(), f)
}
}

impl fmt::Show for Ascii {
impl fmt::Debug for Ascii {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Show::fmt(&(self.chr as char), f)
fmt::Debug::fmt(&(self.chr as char), f)
}
}

Expand Down Expand Up @@ -344,30 +344,30 @@ mod tests {

#[test]
fn test_ascii() {
assert_eq!(65u8.to_ascii().unwrap().as_byte(), 65u8);
assert_eq!(65u8.to_ascii().unwrap().as_char(), 'A');
assert_eq!('A'.to_ascii().unwrap().as_char(), 'A');
assert_eq!('A'.to_ascii().unwrap().as_byte(), 65u8);
assert_eq!(65u8.to_ascii().ok().unwrap().as_byte(), 65u8);
assert_eq!(65u8.to_ascii().ok().unwrap().as_char(), 'A');
assert_eq!('A'.to_ascii().ok().unwrap().as_char(), 'A');
assert_eq!('A'.to_ascii().ok().unwrap().as_byte(), 65u8);

assert!('0'.to_ascii().unwrap().is_digit());
assert!('9'.to_ascii().unwrap().is_digit());
assert!(!'/'.to_ascii().unwrap().is_digit());
assert!(!':'.to_ascii().unwrap().is_digit());
assert!('0'.to_ascii().ok().unwrap().is_digit());
assert!('9'.to_ascii().ok().unwrap().is_digit());
assert!(!'/'.to_ascii().ok().unwrap().is_digit());
assert!(!':'.to_ascii().ok().unwrap().is_digit());

assert!(0x1f_u8.to_ascii().unwrap().is_control());
assert!(!' '.to_ascii().unwrap().is_control());
assert!(0x7f_u8.to_ascii().unwrap().is_control());
assert!(0x1f_u8.to_ascii().ok().unwrap().is_control());
assert!(!' '.to_ascii().ok().unwrap().is_control());
assert!(0x7f_u8.to_ascii().ok().unwrap().is_control());
}

#[test]
fn test_ascii_vec() {
let test = &[40u8, 32u8, 59u8];
let b: &[_] = v2ascii!([40, 32, 59]);
assert_eq!(test.to_ascii().unwrap(), b);
assert_eq!("( ;".to_ascii().unwrap(), b);
assert_eq!(test.to_ascii().ok().unwrap(), b);
assert_eq!("( ;".to_ascii().ok().unwrap(), b);
let v = vec![40u8, 32u8, 59u8];
assert_eq!(v.as_slice().to_ascii().unwrap(), b);
assert_eq!("( ;".to_string().as_slice().to_ascii().unwrap(), b);
assert_eq!(v.as_slice().to_ascii().ok().unwrap(), b);
assert_eq!("( ;".to_string().as_slice().to_ascii().ok().unwrap(), b);
}

#[test]
Expand Down Expand Up @@ -431,7 +431,7 @@ mod tests {

#[test]
fn fmt_string_ascii_slice() {
let s = "abc".to_ascii().unwrap();
let s = "abc".to_ascii().ok().unwrap();
assert_eq!(format!("{}", s), "abc".to_string());
}

Expand Down