-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Follow std library convention and return Option for to_ascii() and into_ascii() instead of failing #12320
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Use explicit unwrap() where needed. Basically rename: * to_ascii_opt -> to_ascii * into_ascii_opt -> into_ascii and get rid of the version which uses fail!
/// Take ownership and cast to an ascii vector. Return None on non-ASCII input. | ||
#[inline] | ||
fn into_ascii_opt(self) -> Option<~[Ascii]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will users want the value of self
back if the conversion fails? It may be worth changing the return type of this to Result<~[Ascii], Self>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good idea.
Return Err(self) from into_ascii() in case of error, so the original value is not lost.
I changed into_ascii() to return a Result as you suggested. |
Fixed by eca39b0 |
@@ -529,21 +513,21 @@ mod tests { | |||
#[test] | |||
fn test_ascii_vec() { | |||
let test = &[40u8, 32u8, 59u8]; | |||
assert_eq!(test.to_ascii(), v2ascii!([40, 32, 59])); | |||
assert_eq!("( ;".to_ascii(), v2ascii!([40, 32, 59])); | |||
assert_eq!(test.to_ascii(), Some(v2ascii!([40, 32, 59]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So assert_eq!(test.to_ascii(), Some(v2ascii!(&[40, 32, 59])));
instead?
Closing due to inactivity, but feel free to reopen with a rebase! |
Hide closure ret hints if ret type is specified Fixes rust-lang#12319
…t-lang#13830) fix rust-lang#12320 When there're multiple attributes, clippy suggests leaving an extra comma and it makes an error. changelog: [`must_use_unit`]: No longer make incorrect suggestions when multiple attributes present.
Return an Option for to_ascii() and into_ascii() functions. Remove to_ascii_opt() and into_ascii_opt().