Skip to content

Instantly share code, notes, and snippets.

@JIghtuse
Last active August 7, 2018 20:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JIghtuse/0e7584e0d4597a57ebbe to your computer and use it in GitHub Desktop.
Save JIghtuse/0e7584e0d4597a57ebbe to your computer and use it in GitHub Desktop.
Rust' Path usage example
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