Skip to content

Instantly share code, notes, and snippets.

@LordMZTE
Last active October 8, 2020 14:39
Show Gist options
  • Save LordMZTE/543ee3ee9a343b1e8e83cd04b8ff16b9 to your computer and use it in GitHub Desktop.
Save LordMZTE/543ee3ee9a343b1e8e83cd04b8ff16b9 to your computer and use it in GitHub Desktop.
use std::fs::File;
use std::path::Path;
/// opens a file from the resources folder
/// takes an `AsRef<Path>` for convenience. with this, a `&str` can be used
fn get_resource(path: impl AsRef<Path>) -> Option<File> {
let mut path_buf = std::env::current_exe().ok()?.parent()?.to_path_buf();
path_buf.push("resources");
path_buf.push(path);
File::open(path_buf).ok()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment