Accept optional target_dir in Model::from_path

This commit is contained in:
Hanno Braun 2022-03-17 14:29:08 +01:00
parent ff20d332c2
commit 99d0ca2b89
2 changed files with 7 additions and 3 deletions

View File

@ -68,7 +68,7 @@ fn main() -> anyhow::Result<()> {
} }
} }
let model = Model::from_path(path)?; let model = Model::from_path(path, None)?;
let mut parameters = HashMap::new(); let mut parameters = HashMap::new();
for parameter in args.parameters { for parameter in args.parameters {

View File

@ -9,7 +9,10 @@ pub struct Model {
} }
impl Model { impl Model {
pub fn from_path(path: PathBuf) -> io::Result<Self> { pub fn from_path(
path: PathBuf,
target_dir: Option<PathBuf>,
) -> io::Result<Self> {
let name = { let name = {
// Can't panic. It only would, if the path ends with "..", and we // Can't panic. It only would, if the path ends with "..", and we
// are canonicalizing it here to prevent that. // are canonicalizing it here to prevent that.
@ -31,7 +34,8 @@ impl Model {
format!("lib{}.so", name) format!("lib{}.so", name)
}; };
path.join("target/debug").join(file) let target_dir = target_dir.unwrap_or_else(|| path.join("target"));
target_dir.join("debug").join(file)
}; };
let manifest_path = path.join("Cargo.toml"); let manifest_path = path.join("Cargo.toml");