Mercurial > touhou
comparison examples/common.rs @ 752:5e5e7136ac92
examples: Return a Result for load_file_into_vec()
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 29 Jan 2020 17:45:25 +0100 |
parents | ee45bfde91bb |
children | a662dddd4a2b |
comparison
equal
deleted
inserted
replaced
751:eab7dde1164f | 752:5e5e7136ac92 |
---|---|
2 use luminance::pixel::{NormRGB8UI, NormRGBA8UI}; | 2 use luminance::pixel::{NormRGB8UI, NormRGBA8UI}; |
3 use luminance::texture::{Dim2, Flat, Sampler, Texture, GenMipmaps}; | 3 use luminance::texture::{Dim2, Flat, Sampler, Texture, GenMipmaps}; |
4 use luminance_glfw::GlfwSurface; | 4 use luminance_glfw::GlfwSurface; |
5 use touhou::th06::anm0::Anm0; | 5 use touhou::th06::anm0::Anm0; |
6 use std::fs::File; | 6 use std::fs::File; |
7 use std::io::{BufReader, Read}; | 7 use std::io::{self, BufReader, Read}; |
8 use std::path::Path; | 8 use std::path::Path; |
9 | 9 |
10 pub fn load_file_into_vec<P: AsRef<Path>>(filename: P) -> Vec<u8> { | 10 pub fn load_file_into_vec<P: AsRef<Path>>(filename: P) -> io::Result<Vec<u8>> { |
11 let file = File::open(filename).unwrap(); | 11 let file = File::open(filename)?; |
12 let mut file = BufReader::new(file); | 12 let mut file = BufReader::new(file); |
13 let mut buf = vec![]; | 13 let mut buf = vec![]; |
14 file.read_to_end(&mut buf).unwrap(); | 14 file.read_to_end(&mut buf)?; |
15 buf | 15 Ok(buf) |
16 } | 16 } |
17 | 17 |
18 pub enum LoadedTexture { | 18 pub enum LoadedTexture { |
19 Rgba(Texture<Flat, Dim2, NormRGBA8UI>), | 19 Rgba(Texture<Flat, Dim2, NormRGBA8UI>), |
20 Rgb(Texture<Flat, Dim2, NormRGB8UI>), | 20 Rgb(Texture<Flat, Dim2, NormRGB8UI>), |