1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! This crate contains decoding functions for the embedded icons of
//! several video game console ROM formats.
//!
//! The main use-case is to write thumbnailers for file managers.
use camino::Utf8PathBuf;

pub mod error;
pub mod image;
pub mod nds;

/// Extracts the thumbnail for a given `path` as an `image::RgbaImage`.
///
/// # Errors
/// All errors are contained in variants of the [`ThumbnailerError`] enum.
///
/// [`ThumbnailerError`]: error/enum.ThumbnailerError.html
///
pub fn extract_thumbnail(path: &str) -> Result<image::Image, error::ThumbnailerError> {
    let path = Utf8PathBuf::from(path);
    match path.extension() {
        None => Err(error::ThumbnailerError::NoExtension),
        Some(ext) => match ext {
            "nds" => nds::extract_thumbnail(&path),
            _ => Err(error::ThumbnailerError::UnsupportedExtension),
        },
    }
}