/// Load a skin element's texture
///
/// This function takes the basename and tries different paths until it finds one that exists
Load a skin element's texture
This function takes the basename and tries different paths until it finds one that exists
Load a skin element ' s texture This function takes the basename and tries different paths until it finds one that exists
fn load_texture<F, T>(
    factory: &mut F,
    cache: &mut HashMap<String, Rc<[Rc<T>]>>,
    dir: &path::Path,
    default_dir: &path::Path,
    names: &(&'static str, String),
    texture_settings: &TextureSettings,
) -> Result<Rc<T>, ParseError>
where
    T: CreateTexture<F>,
    T::Error: ToString,
{
    macro_rules! repetitive_code {
        // $dir should be a path::Path
        ($(($dir:ident, $name:expr)),*) => {$(
            // Check the cache
            if let Some(texture) = cache.get(&$name) {
                return Ok(Rc::clone(&texture[0]));
            }
            // TODO can these join's be optimized? how much time does it take to allocate the pathbuf?
            let path = $dir.join($name + ".png");
            if path.exists() {
                let texture = texture_from_path(factory, path, texture_settings)?;
                let rc = Rc::new(texture);
                cache.insert($name, Rc::from(&[Rc::clone(&rc)][..]));
                return Ok(rc);
            }
        )*}
    }
    // Check the skin directory, then the default skin directory
    repetitive_code!((dir, names.1.clone()), (default_dir, names.0.to_owned()));
    Err(OsuSkinParseError::NoDefaultTexture(String::from(names.0)).into())
}
fn load_texture < F , T > ( factory : & mut F , cache : & mut HashMap < String , Rc < [ Rc < T > ] > > , dir : & path :: Path , default_dir : & path :: Path , names : & ( & ' static str , String ) , texture_settings : & TextureSettings , ) -> Result < Rc < T > , ParseError > where T : CreateTexture < F > , T :: Error : ToString , { macro_rules! repetitive_code { // $dir should be a path::Path ( $ ( ( $dir : ident $name : expr ) ) * ) => { $ ( // Check the cache if let Some ( texture ) cache get ( $name ) { return Ok ( Rc clone ( texture [ 0 ] ) ) } // TODO can these join's be optimized? how much time does it take to allocate the pathbuf? let path $dir join ( $name " " ) if path exists ( ) { let texture texture_from_path ( factory path texture_settings ) let rc Rc new ( texture ) cache insert ( $name Rc from ( [ Rc clone ( rc ) ] [ ] ) ) return Ok ( rc ) } ) * } } // Check the skin directory, then the default skin directory repetitive_code ! ( ( dir names 1 clone ( ) ) ( default_dir names 0 to_owned ( ) ) ) ; Err ( OsuSkinParseError :: NoDefaultTexture ( String :: from ( names . 0 ) ) . into ( ) ) }
Load a skin element's texture
This function takes the basename and tries different paths until it finds one that exists
Load a skin element ' s texture This function takes the basename and tries different paths until it finds one that exists
factory
&mut F
cache
&mut HashMap<String, Rc<[Rc<T>]>>
dir
&path::Path
default_dir
&path::Path
names
&(&'static str, String)
texture_settings
&TextureSettings