update str::from_utf8

This commit is contained in:
Sean McArthur
2014-12-23 12:55:53 -08:00
parent 33f61213ce
commit 691c70a380
9 changed files with 20 additions and 18 deletions

View File

@@ -11,8 +11,8 @@ pub fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> {
}
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
match from_utf8(unsafe { raw[].unsafe_get(0)[] }) {
Some(s) => FromStr::from_str(s),
None => None
Ok(s) => FromStr::from_str(s),
Err(_) => None
}
}
@@ -29,13 +29,13 @@ pub fn from_comma_delimited<T: FromStr>(raw: &[Vec<u8>]) -> Option<Vec<T>> {
/// Reads a comma-delimited raw string into a Vec.
pub fn from_one_comma_delimited<T: FromStr>(raw: &[u8]) -> Option<Vec<T>> {
match from_utf8(raw) {
Some(s) => {
Ok(s) => {
Some(s.as_slice()
.split([',', ' '].as_slice())
.filter_map(from_str)
.collect())
}
None => None
Err(_) => None
}
}