gdritter repos thermidor / 24aba4d
Borrow a vec to fix an error Getty Ritter 6 years ago
4 changed file(s) with 26 addition(s) and 26 deletion(s). Collapse all Expand all
99 fn parse_pixel<Rd>(r: &mut ByteReader<Rd>) -> Result<(u16,u16,u16,u16), String>
1010 where Rd: Iterator<Item=u8>
1111 {
12 Ok((try!(r.read_u16be()),
13 try!(r.read_u16be()),
14 try!(r.read_u16be()),
15 try!(r.read_u16be())))
12 Ok((r.read_u16be()?,
13 r.read_u16be()?,
14 r.read_u16be()?,
15 r.read_u16be()?))
1616 }
1717
1818 impl FFImage {
3636 pub fn from_reader<Rd>(r: &mut ByteReader<Rd>) -> Result<FFImage, String>
3737 where Rd: Iterator<Item=u8>
3838 {
39 assert!(try!(r.next()) == 'f' as u8);
40 assert!(try!(r.next()) == 'a' as u8);
41 assert!(try!(r.next()) == 'r' as u8);
42 assert!(try!(r.next()) == 'b' as u8);
43 assert!(try!(r.next()) == 'f' as u8);
44 assert!(try!(r.next()) == 'e' as u8);
45 assert!(try!(r.next()) == 'l' as u8);
46 assert!(try!(r.next()) == 'd' as u8);
39 assert!(r.next()? == 'f' as u8);
40 assert!(r.next()? == 'a' as u8);
41 assert!(r.next()? == 'r' as u8);
42 assert!(r.next()? == 'b' as u8);
43 assert!(r.next()? == 'f' as u8);
44 assert!(r.next()? == 'e' as u8);
45 assert!(r.next()? == 'l' as u8);
46 assert!(r.next()? == 'd' as u8);
4747
4848 let w = try!(r.read_u32be());
4949 let h = try!(r.read_u32be());
7171 let img = image::load(Cursor::new(tex.clone()),
7272 image::PNG).unwrap().to_rgba();
7373 let dims = img.dimensions();
74 let img = RawImage2d::from_raw_rgba_reversed(img.into_raw(),
74 let img = RawImage2d::from_raw_rgba_reversed(&img.into_raw(),
7575 dims);
7676 Some(Texture2d::new(display, img).unwrap())
7777 } else {
3333 '"' => parse_string(s),
3434 _ if c.is_digit(10) || c == '-' => parse_num(c, s),
3535 _ if c.is_alphabetic() =>
36 Ok(Adnot::Sym(try!(parse_sym(c, s)))),
37 _ => fail(&format!("Invalid character: {:?}", c)),
36 Ok(Adnot::Sym(parse_sym(c, s)?)),
37 _ => Err(AdnotError { message: format!("Invalid character: {:?}", c) }),
3838 }
3939 } else {
4040 fail("Unexpected end of input")
4949 s.next();
5050 return Ok(Adnot::List(vec));
5151 } else {
52 vec.push(try!(parse_val(s)));
52 vec.push(parse_val(s)?);
5353 }
5454 }
5555 }
6262 Some(_) => { return fail("Expected a tagname character") }
6363 None => { return fail("Unexpected end of input") }
6464 };
65 let name = try!(parse_sym(first, s));
65 let name = parse_sym(first, s)?;
6666 loop {
6767 skip_space(s);
6868 if let Some(&')') = s.peek() {
6969 s.next();
7070 return Ok(Adnot::Sum(name, vec));
7171 } else {
72 vec.push(try!(parse_val(s)));
72 vec.push(parse_val(s)?);
7373 }
7474 }
7575 }
8888 Some(_) => { return fail("Expected a tagname character") }
8989 None => { return fail("Unexpected end of input") }
9090 };
91 let key = try!(parse_sym(first, s));
91 let key = parse_sym(first, s)?;
9292 skip_space(s);
93 let val = try!(parse_val(s));
93 let val = parse_val(s)?;
9494 map.insert(key, val);
9595 }
9696 }
178178 Ok(ret)
179179 }
180180
181 /// This reads a PrefixInteger to find out how many other things to read,
182 /// and then reads that number of things.
181 /// This reads a PrefixInteger to find out how many other things
182 /// to read, and then reads that number of things.
183183 pub fn read_several<F, R>(&mut self, reader: F) -> Result<Vec<R>, String>
184184 where F: Fn(&mut ByteReader<T>) -> Result<R, String>
185185 {
191191 Ok(ret)
192192 }
193193
194 /// This reads a PrefixInteger number of bytes, and then parses those
195 /// bytes as a UTF-8 string. This means, importantly, that we cannot
196 /// naïvely produce values intended to be parsed with this using a
197 /// basic string length.
194 /// This reads a PrefixInteger number of bytes, and then parses
195 /// those bytes as a UTF-8 string. This means, importantly, that
196 /// we cannot naïvely produce values intended to be parsed with
197 /// this using a basic string length.
198198 pub fn read_string(&mut self) -> Result<String, String> {
199199 let raw_bytes = try!(self.read_several(|r| r.next()));
200200 match String::from_utf8(raw_bytes) {