Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a read only embedded FileSystem implementation backed by rust-embed #12

Merged
merged 2 commits into from
Oct 9, 2020
Merged

Conversation

ahouts
Copy link
Contributor

@ahouts ahouts commented Oct 7, 2020

Adds a read only embedded FileSystem implementation backed by rust-embed.

The API of rust-embed is very simplistic, so if we were to implement FileSystem.read_dir without some kind of cache we would have to iterate through the entire directory listing every time. To prevent this I chose to use a radix trie to store the paths of files and directories when EmbeddedFs is constructed.

Both added dependencies are optional and gated behind a feature flag, so users who do not explicitly ask for embedded file system support will not need to download/compile them.

@@ -9,4 +9,5 @@ matrix:
allow_failures:
- rust: nightly
- rust: beta
script: cargo build --verbose && cargo test --verbose
script: cargo build --verbose && cargo test --verbose &&
cargo build --verbose --all-features && cargo test --verbose --all-features
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to show the tests pass, not sure what approach you want to take for this.

@@ -14,7 +14,11 @@ travis-ci = { repository = "manuel-woelker/rust-vfs", branch = "master" }

[dependencies]
thiserror = "1.0"
rust-embed = { version = "5.6", optional = true }
radix_trie = { version = "0.1", optional = true }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally old version to support 1.32.0, the most recent version supports 1.36.0 due to a transient dependency on smallvec.

@ahouts ahouts marked this pull request as ready for review October 7, 2020 04:41
fn child_elements<'a>(
d: &'a Path,
t: SubTrie<'a, String, bool>,
) -> Box<dyn Iterator<Item = String> + 'a> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If performance turns out to be an issue the dynamic iterator here could be replaced with an enum where each variant is one of the concrete types below.

@manuel-woelker manuel-woelker merged commit 5a872c7 into manuel-woelker:master Oct 9, 2020
@manuel-woelker
Copy link
Owner

Thanks for the PR! Should be great for fully self-contained executables.

I imagine in some cases all the paths accessed in the embedded FS are known by the application anyway, so read_dir() and the supporting trie might not even be needed.

@ahouts ahouts deleted the add-embedded-fs branch October 10, 2020 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants