comparison examples/common.rs @ 740:8d29dac12219

examples: Make the common functions take AsRef<Path>.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 06 Jan 2020 22:48:09 +0100
parents d5d5496e4e53
children 90e907859bae
comparison
equal deleted inserted replaced
739:01915da33b99 740:8d29dac12219
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::{BufReader, Read};
8 use std::path::Path; 8 use std::path::Path;
9 9
10 pub fn load_file_into_vec(filename: &Path) -> Vec<u8> { 10 pub fn load_file_into_vec<P: AsRef<Path>>(filename: P) -> Vec<u8> {
11 let file = File::open(filename).unwrap(); 11 let file = File::open(filename).unwrap();
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).unwrap();
15 buf 15 buf
94 Err(TextureLoadError::CannotOpenAlpha(alpha.to_str().unwrap().to_owned(), e)) 94 Err(TextureLoadError::CannotOpenAlpha(alpha.to_str().unwrap().to_owned(), e))
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 pub fn load_anm_image(mut surface: &mut GlfwSurface, anm0: &Anm0, anm_filename: &Path) -> Result<LoadedTexture, TextureLoadError> { 99 pub fn load_anm_image<P: AsRef<Path>>(mut surface: &mut GlfwSurface, anm0: &Anm0, anm_filename: P) -> Result<LoadedTexture, TextureLoadError> {
100 let anm_filename = anm_filename.as_ref();
100 let png_filename = anm_filename.with_file_name(Path::new(&anm0.png_filename).file_name().unwrap()); 101 let png_filename = anm_filename.with_file_name(Path::new(&anm0.png_filename).file_name().unwrap());
101 match anm0.alpha_filename { 102 match anm0.alpha_filename {
102 Some(ref filename) => { 103 Some(ref filename) => {
103 let alpha_filename = anm_filename.with_file_name(Path::new(filename).file_name().unwrap()); 104 let alpha_filename = anm_filename.with_file_name(Path::new(filename).file_name().unwrap());
104 load_rgb_a_pngs(&mut surface, &png_filename, &alpha_filename) 105 load_rgb_a_pngs(&mut surface, &png_filename, &alpha_filename)