Skip to content

Commit 96ae57c

Browse files
committed
Rename to_ascii_opt and into_ascii_opt to to_ascii and into_ascii.
1 parent 79f21e6 commit 96ae57c

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/lib.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> fmt::Show for Ascii {
147147
pub trait AsciiCast<T, U = Self> for Sized?: AsciiExt<U> {
148148
/// Convert to an ascii type, return None on non-ASCII input.
149149
#[inline]
150-
fn to_ascii_opt(&self) -> Option<T> {
150+
fn to_ascii(&self) -> Option<T> {
151151
if self.is_ascii() {
152152
Some(unsafe { self.to_ascii_nocheck() })
153153
} else {
@@ -197,7 +197,7 @@ pub trait OwnedAsciiCast<Sized? T, U = Self>
197197
where T: BorrowFrom<Self> + AsciiExt<U> {
198198
/// Take ownership and cast to an ascii vector. Return None on non-ASCII input.
199199
#[inline]
200-
fn into_ascii_opt(self) -> Option<Vec<Ascii>> {
200+
fn into_ascii(self) -> Option<Vec<Ascii>> {
201201
if {
202202
let borrowed: &T = BorrowFrom::borrow_from(&self);
203203
borrowed.is_ascii()
@@ -306,30 +306,30 @@ mod tests {
306306

307307
#[test]
308308
fn test_ascii() {
309-
assert_eq!(65u8.to_ascii_opt().unwrap().as_byte(), 65u8);
310-
assert_eq!(65u8.to_ascii_opt().unwrap().as_char(), 'A');
311-
assert_eq!('A'.to_ascii_opt().unwrap().as_char(), 'A');
312-
assert_eq!('A'.to_ascii_opt().unwrap().as_byte(), 65u8);
309+
assert_eq!(65u8.to_ascii().unwrap().as_byte(), 65u8);
310+
assert_eq!(65u8.to_ascii().unwrap().as_char(), 'A');
311+
assert_eq!('A'.to_ascii().unwrap().as_char(), 'A');
312+
assert_eq!('A'.to_ascii().unwrap().as_byte(), 65u8);
313313

314-
assert!('0'.to_ascii_opt().unwrap().is_digit());
315-
assert!('9'.to_ascii_opt().unwrap().is_digit());
316-
assert!(!'/'.to_ascii_opt().unwrap().is_digit());
317-
assert!(!':'.to_ascii_opt().unwrap().is_digit());
314+
assert!('0'.to_ascii().unwrap().is_digit());
315+
assert!('9'.to_ascii().unwrap().is_digit());
316+
assert!(!'/'.to_ascii().unwrap().is_digit());
317+
assert!(!':'.to_ascii().unwrap().is_digit());
318318

319-
assert!((0x1fu8).to_ascii_opt().unwrap().is_control());
320-
assert!(!' '.to_ascii_opt().unwrap().is_control());
321-
assert!((0x7fu8).to_ascii_opt().unwrap().is_control());
319+
assert!((0x1fu8).to_ascii().unwrap().is_control());
320+
assert!(!' '.to_ascii().unwrap().is_control());
321+
assert!((0x7fu8).to_ascii().unwrap().is_control());
322322
}
323323

324324
#[test]
325325
fn test_ascii_vec() {
326326
let test = &[40u8, 32u8, 59u8];
327327
let b: &[_] = v2ascii!([40, 32, 59]);
328-
assert_eq!(test.to_ascii_opt().unwrap(), b);
329-
assert_eq!("( ;".to_ascii_opt().unwrap(), b);
328+
assert_eq!(test.to_ascii().unwrap(), b);
329+
assert_eq!("( ;".to_ascii().unwrap(), b);
330330
let v = vec![40u8, 32u8, 59u8];
331-
assert_eq!(v.as_slice().to_ascii_opt().unwrap(), b);
332-
assert_eq!("( ;".to_string().as_slice().to_ascii_opt().unwrap(), b);
331+
assert_eq!(v.as_slice().to_ascii().unwrap(), b);
332+
assert_eq!("( ;".to_string().as_slice().to_ascii().unwrap(), b);
333333
}
334334

335335
#[test]
@@ -357,32 +357,32 @@ mod tests {
357357

358358
#[test]
359359
fn test_opt() {
360-
assert_eq!(65u8.to_ascii_opt(), Some(Ascii { chr: 65u8 }));
361-
assert_eq!(255u8.to_ascii_opt(), None);
360+
assert_eq!(65u8.to_ascii(), Some(Ascii { chr: 65u8 }));
361+
assert_eq!(255u8.to_ascii(), None);
362362

363-
assert_eq!('A'.to_ascii_opt(), Some(Ascii { chr: 65u8 }));
364-
assert_eq!('λ'.to_ascii_opt(), None);
363+
assert_eq!('A'.to_ascii(), Some(Ascii { chr: 65u8 }));
364+
assert_eq!('λ'.to_ascii(), None);
365365

366-
assert_eq!("zoä华".to_ascii_opt(), None);
366+
assert_eq!("zoä华".to_ascii(), None);
367367

368368
let test1 = &[127u8, 128u8, 255u8];
369-
assert_eq!((test1).to_ascii_opt(), None);
369+
assert_eq!((test1).to_ascii(), None);
370370

371371
let v = [40u8, 32u8, 59u8];
372372
let v2: &[_] = v2ascii!(&[40, 32, 59]);
373-
assert_eq!(v.to_ascii_opt(), Some(v2));
373+
assert_eq!(v.to_ascii(), Some(v2));
374374
let v = [127u8, 128u8, 255u8];
375-
assert_eq!(v.to_ascii_opt(), None);
375+
assert_eq!(v.to_ascii(), None);
376376

377377
let v = "( ;";
378-
assert_eq!(v.to_ascii_opt(), Some(v2));
379-
assert_eq!("zoä华".to_ascii_opt(), None);
378+
assert_eq!(v.to_ascii(), Some(v2));
379+
assert_eq!("zoä华".to_ascii(), None);
380380

381-
assert_eq!((vec![40u8, 32u8, 59u8]).into_ascii_opt(), Some(vec2ascii![40, 32, 59]));
382-
assert_eq!((vec![127u8, 128u8, 255u8]).into_ascii_opt(), None);
381+
assert_eq!((vec![40u8, 32u8, 59u8]).into_ascii(), Some(vec2ascii![40, 32, 59]));
382+
assert_eq!((vec![127u8, 128u8, 255u8]).into_ascii(), None);
383383

384-
assert_eq!(("( ;".to_string()).into_ascii_opt(), Some(vec2ascii![40, 32, 59]));
385-
assert_eq!(("zoä华".to_string()).into_ascii_opt(), None);
384+
assert_eq!(("( ;".to_string()).into_ascii(), Some(vec2ascii![40, 32, 59]));
385+
assert_eq!(("zoä华".to_string()).into_ascii(), None);
386386
}
387387

388388
#[test]

0 commit comments

Comments
 (0)