Skip to content

Commit

Permalink
Rm glob, expose internals
Browse files Browse the repository at this point in the history
  • Loading branch information
azdavis committed Feb 27, 2024
1 parent a603e6b commit c42a13d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pedantic = "deny"
[workspace.dependencies]
drop_bomb = "0.1.5"
dunce = "1.0.4"
glob = "0.3.1"
line-index = "0.1.1"
log = "0.4.20"
nohash-hasher = "0.2.0"
Expand Down
1 change: 0 additions & 1 deletion crates/paths/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ workspace = true

[dependencies]
dunce.workspace = true
glob.workspace = true
nohash-hasher.workspace = true

fast-hash.path = "../fast-hash"
Expand Down
19 changes: 9 additions & 10 deletions crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Types for working with paths.
pub use glob::{GlobError, PatternError};

use fast_hash::FxHashMap;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -223,23 +221,24 @@ impl FileSystem for RealFileSystem {
/// - Have `..`
/// - Do not start with `/`
///
/// Also, using `glob` doesn't actually glob.
///
/// But this is mainly intended for basic testing purposes, so it's fine.
#[derive(Debug, Default)]
pub struct MemoryFileSystem(FxHashMap<PathBuf, String>);
pub struct MemoryFileSystem {
/// The in-memory storage.
pub inner: FxHashMap<PathBuf, String>,
}

impl MemoryFileSystem {
/// Returns a new `MemoryFileSystem`.
#[must_use]
pub fn new(map: FxHashMap<PathBuf, String>) -> Self {
Self(map)
pub fn new(inner: FxHashMap<PathBuf, String>) -> Self {
Self { inner }
}
}

impl FileSystem for MemoryFileSystem {
fn read_to_string(&self, path: &Path) -> std::io::Result<String> {
match self.0.get(path) {
match self.inner.get(path) {
Some(x) => Ok(x.clone()),
None => Err(std::io::Error::from(std::io::ErrorKind::NotFound)),
}
Expand All @@ -250,11 +249,11 @@ impl FileSystem for MemoryFileSystem {
}

fn read_dir(&self, path: &Path) -> std::io::Result<Vec<PathBuf>> {
Ok(self.0.keys().filter(|&p| p.starts_with(path) && p != path).cloned().collect())
Ok(self.inner.keys().filter(|&p| p.starts_with(path) && p != path).cloned().collect())
}

fn is_file(&self, path: &Path) -> bool {
self.0.contains_key(path)
self.inner.contains_key(path)
}

fn canonical(&self, path: &Path) -> std::io::Result<CanonicalPathBuf> {
Expand Down

0 comments on commit c42a13d

Please sign in to comment.