Skip to content

Commit

Permalink
Changing Borrow<Path> to AsRef<Path> to follow suit with Rust std…
Browse files Browse the repository at this point in the history
…lib. Although both are appropriate in this case, `AsRef` is a more fundamental trait
  • Loading branch information
luketpeterson committed Oct 24, 2023
1 parent 2062ec8 commit 2e336be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/src/metta/runner/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl EnvBuilder {
///
/// NOTE: The most recently added paths will have the highest search priority, save for the `working_dir`,
/// and paths returned first by the iterator will have higher priority within the same call to add_include_paths.
pub fn add_include_paths<P: Borrow<Path>, I: IntoIterator<Item=P>>(mut self, paths: I) -> Self {
let mut additional_paths: Vec<PathBuf> = paths.into_iter().map(|path| path.borrow().into()).collect();
pub fn add_include_paths<P: AsRef<Path>, I: IntoIterator<Item=P>>(mut self, paths: I) -> Self {
let mut additional_paths: Vec<PathBuf> = paths.into_iter().map(|path| path.as_ref().into()).collect();
additional_paths.extend(self.env.extra_include_paths);
self.env.extra_include_paths = additional_paths;
self
Expand Down
5 changes: 2 additions & 3 deletions lib/src/metta/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use super::space::*;
use super::text::{Tokenizer, SExprParser};
use super::types::validate_atom;

use core::borrow::Borrow;
use std::rc::Rc;
use std::path::{Path, PathBuf};
use std::collections::HashMap;
Expand Down Expand Up @@ -243,8 +242,8 @@ impl Metta {
}

/// Runs the MeTTa code in the specified file
pub fn run_from_file<P: Borrow<Path>>(&self, program_path: P) -> Result<Vec<Vec<Atom>>, String> {
let path = program_path.borrow();
pub fn run_from_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<Vec<Atom>>, String> {
let path = path.as_ref();
let program = std::fs::read_to_string(path)
.map_err(|err| format!("Could not read file, path: {}, error: {}", path.display(), err))?;
self.run(SExprParser::new(program.as_str()))
Expand Down

0 comments on commit 2e336be

Please sign in to comment.