pathfinder_resources/
embedded.rs

1// pathfinder/resources/src/embedded.rs
2//
3// Copyright © 2020 The Pathfinder Project Developers.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Embeds needed resources statically in the binary.
12
13use crate::ResourceLoader;
14use std::io::{Error as IOError, ErrorKind};
15
16include!(concat!(env!("OUT_DIR"), "/manifest.rs"));
17
18pub struct EmbeddedResourceLoader;
19
20impl EmbeddedResourceLoader {
21    #[inline]
22    pub fn new() -> EmbeddedResourceLoader {
23        EmbeddedResourceLoader
24    }
25}
26
27impl ResourceLoader for EmbeddedResourceLoader {
28    fn slurp(&self, virtual_path: &str) -> Result<Vec<u8>, IOError> {
29        match RESOURCES.iter().filter(|&(path, _)| *path == virtual_path).next() {
30            Some((_, data)) => Ok(data.to_vec()),
31            None => Err(IOError::from(ErrorKind::NotFound)),
32        }
33    }
34}