Mercurial > touhou
diff src/th06/anm0.rs @ 701:b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 23 Aug 2019 15:34:03 +0200 |
parents | 3ff1af76e413 |
children | 718348c7608e |
line wrap: on
line diff
--- a/src/th06/anm0.rs +++ b/src/th06/anm0.rs @@ -70,11 +70,8 @@ pub struct Anm0 { impl Anm0 { /// Parse a slice of bytes into an `Anm0` struct. - pub fn from_slice(data: &[u8]) -> Result<Anm0, ()> { - // XXX: report the exact nom error instead! - let (_, anm0) = parse_anm0(data).or_else(|_| Err(()))?; - assert_eq!(anm0.len(), 1); - Ok(anm0[0].clone()) + pub fn from_slice(data: &[u8]) -> IResult<&[u8], Vec<Anm0>> { + parse_anm0(data) } /// TODO @@ -318,7 +315,9 @@ mod tests { let mut file = io::BufReader::new(file); let mut buf = vec![]; file.read_to_end(&mut buf).unwrap(); - let anm0 = Anm0::from_slice(&buf).unwrap(); + let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); + assert_eq!(anms.len(), 1); + let anm0 = anms.pop().unwrap(); assert_eq!(anm0.size, (256, 256)); assert_eq!(anm0.format, 5); }