refactor: &PathBuf -> &Path
This commit is contained in:
parent
03c5a8540d
commit
8dd65ccbc0
2 changed files with 15 additions and 15 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use super::write_file;
|
||||
use anyhow::{Context, Result};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::{fs, str};
|
||||
|
||||
const BINDING_CC_TEMPLATE: &str = include_str!("./templates/binding.cc");
|
||||
|
|
@ -24,7 +24,7 @@ pub fn generate_binding_files(repo_path: &Path, language_name: &str) -> Result<(
|
|||
|
||||
// Generate rust bindings if needed.
|
||||
let rust_binding_dir = bindings_dir.join("rust");
|
||||
create_path(&rust_binding_dir, |path| create_dir(path))?;
|
||||
create_path(&rust_binding_dir, create_dir)?;
|
||||
|
||||
create_path(&rust_binding_dir.join("lib.rs"), |path| {
|
||||
generate_file(path, LIB_RS_TEMPLATE, language_name)
|
||||
|
|
@ -40,7 +40,7 @@ pub fn generate_binding_files(repo_path: &Path, language_name: &str) -> Result<(
|
|||
|
||||
// Generate node bindings
|
||||
let node_binding_dir = bindings_dir.join("node");
|
||||
create_path(&node_binding_dir, |path| create_dir(path))?;
|
||||
create_path(&node_binding_dir, create_dir)?;
|
||||
|
||||
create_path(&node_binding_dir.join("index.js"), |path| {
|
||||
generate_file(path, INDEX_JS_TEMPLATE, language_name)
|
||||
|
|
@ -128,9 +128,9 @@ fn create_dir(path: &Path) -> Result<()> {
|
|||
.with_context(|| format!("Failed to create {:?}", path.to_string_lossy()))
|
||||
}
|
||||
|
||||
fn create_path<F>(path: &PathBuf, action: F) -> Result<bool>
|
||||
fn create_path<F>(path: &Path, action: F) -> Result<bool>
|
||||
where
|
||||
F: Fn(&PathBuf) -> Result<()>,
|
||||
F: Fn(&Path) -> Result<()>,
|
||||
{
|
||||
if !path.exists() {
|
||||
action(path)?;
|
||||
|
|
@ -139,10 +139,10 @@ where
|
|||
Ok(false)
|
||||
}
|
||||
|
||||
fn create_path_else<T, F>(path: &PathBuf, action: T, else_action: F) -> Result<bool>
|
||||
fn create_path_else<T, F>(path: &Path, action: T, else_action: F) -> Result<bool>
|
||||
where
|
||||
T: Fn(&PathBuf) -> Result<()>,
|
||||
F: Fn(&PathBuf) -> Result<()>,
|
||||
T: Fn(&Path) -> Result<()>,
|
||||
F: Fn(&Path) -> Result<()>,
|
||||
{
|
||||
if !path.exists() {
|
||||
action(path)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue