-
-
Save GopherJ/da1bf5fbd449b94869b22bc2e6dcb62c to your computer and use it in GitHub Desktop.
Rust' Path usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::path::{Path, PathBuf}; | |
struct Model { | |
u: f32, | |
} | |
fn texture_fname(path: &Path) -> PathBuf { | |
let fullname = format!("{}{}", path.file_stem().unwrap().to_str().unwrap(), "_diffuse"); | |
let mut buf = PathBuf::from(path); | |
buf.set_file_name(fullname); | |
buf.set_extension("tga"); | |
buf | |
} | |
impl Model { | |
fn new(texture_path: &Path) -> Model { | |
let texture_path = texture_fname(texture_path); | |
println!("path: {:?}", texture_path.as_path()); | |
// outputs 'path: "/tmp/models/african_head_diffuse.tga"' | |
Model{ u: 1.0 } | |
} | |
} | |
fn main() { | |
let model = Model::new(Path::new("/tmp/models/african_head.obj")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment