Skip to content

Commit

Permalink
Clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Aug 14, 2024
1 parent 6386e04 commit 5267e54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions jaq-syn/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Arena(typed_arena::Arena<String>);

/// Combined file loader, lexer, and parser for multiple modules.
pub struct Loader<S, R> {
#[allow(clippy::type_complexity)]
mods: Vec<(File<S>, Result<Module<S>, Error<S>>)>,
/// function to read module file contents from a path
read: R,
Expand All @@ -27,6 +28,8 @@ pub struct Loader<S, R> {
open: Vec<S>,
}

type ReadFn = fn(&str) -> Result<String, String>;

/// Path and contents of a (module) file, both represented by `S`.
///
/// This is useful for creating precise error messages.
Expand Down Expand Up @@ -137,7 +140,7 @@ impl<S, B> Module<S, B> {
}
}

impl<'s> Loader<&'s str, fn(&str) -> Result<String, String>> {
impl<'s> Loader<&'s str, ReadFn> {
/// Initialise the loader with prelude definitions.
///
/// The prelude is a special module that is implicitly included by all other modules
Expand Down Expand Up @@ -212,7 +215,7 @@ impl<S, R> Loader<S, R> {

/// Read the contents of included/imported module files by performing file I/O.
#[cfg(feature = "std")]
pub fn with_std_read(self) -> Loader<S, fn(&str) -> Result<String, String>> {
pub fn with_std_read(self) -> Loader<S, ReadFn> {
self.with_read(std_read)
}
}
Expand Down
8 changes: 4 additions & 4 deletions jaq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ fn parse(path: &str, code: &str, vars: &[String]) -> Result<(Vec<Val>, Filter),
.map_err(load_errors)?;

let mut vals = Vec::new();
import(&modules, |path| {
Ok(vals.push(json_array(path).map_err(|e| e.to_string())?))
import(&modules, |p| {
vals.push(json_array(p).map_err(|e| e.to_string())?);
Ok(())
})
.map_err(load_errors)?;

Expand Down Expand Up @@ -341,8 +342,7 @@ fn json_read<'a>(read: impl BufRead + 'a) -> impl Iterator<Item = io::Result<Val
}

fn json_array(path: impl AsRef<Path>) -> io::Result<Val> {
let file = load_file(path.as_ref())?;
Ok(json_slice(&file).collect::<Result<Val, _>>()?)
json_slice(&load_file(path.as_ref())?).collect()
}

fn read_buffered<'a, R>(cli: &Cli, read: R) -> Box<dyn Iterator<Item = io::Result<Val>> + 'a>
Expand Down

0 comments on commit 5267e54

Please sign in to comment.