forked from rojo-rbx/rojo
* add install command * cargo fmt * filter spec files * Update src/cli/plugin.rs Co-Authored-By: Lucien Greathouse <me@lpghatguy.com> * Update src/cli/plugin.rs Co-Authored-By: Lucien Greathouse <me@lpghatguy.com> * fix comments * encode plugin with rbx_binary * update build script * refactor pathbuf error into io error * fix rojo typo * remove snafu * Update `snapshot_from_fs_path` * Print `rerun-if-changed` even for directories, in order to run the build.rs script when files are added. * Switch `filter_map` loop to a regular for loop. I like the FP-style iterator stuff in Rust, but I think Result handling is easier in a normal loop. Also, I don't believe the result of read_dir implements `ExactSizedIterator`, so some of the wins of map+collect aren't there. * Replace Result::unwrap with ? in build.rs * Simplify error handling code in runtime * Checkout with submodules Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
46 lines
1013 B
Rust
46 lines
1013 B
Rust
use serde::{Deserialize, Serialize};
|
|
use std::collections::BTreeMap;
|
|
|
|
/// A slice of a tree of files. Can be loaded into an
|
|
/// [`InMemoryFs`](struct.InMemoryFs.html).
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
#[non_exhaustive]
|
|
pub enum VfsSnapshot {
|
|
File {
|
|
contents: Vec<u8>,
|
|
},
|
|
|
|
Dir {
|
|
children: BTreeMap<String, VfsSnapshot>,
|
|
},
|
|
}
|
|
|
|
impl VfsSnapshot {
|
|
pub fn file<C: Into<Vec<u8>>>(contents: C) -> Self {
|
|
Self::File {
|
|
contents: contents.into(),
|
|
}
|
|
}
|
|
|
|
pub fn dir<K: Into<String>, I: IntoIterator<Item = (K, VfsSnapshot)>>(children: I) -> Self {
|
|
Self::Dir {
|
|
children: children
|
|
.into_iter()
|
|
.map(|(key, value)| (key.into(), value))
|
|
.collect(),
|
|
}
|
|
}
|
|
|
|
pub fn empty_file() -> Self {
|
|
Self::File {
|
|
contents: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn empty_dir() -> Self {
|
|
Self::Dir {
|
|
children: BTreeMap::new(),
|
|
}
|
|
}
|
|
}
|