mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Normalize metadata into metadata per instance and metadata per path (#107)
* Begin the metadata merge trek * Tidy up path metadata, entry API, begin implementing * Flesh out use of PathMap Entry API * Metadata per instance is a go * Tidy up naming for metadata per instance * SnapshotMetadata -> SnapshotContext
This commit is contained in:
committed by
GitHub
parent
4cfdc72c00
commit
bd3a4a719d
@@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
collections::hash_map,
|
||||
path::{self, Path, PathBuf},
|
||||
collections::{HashMap, HashSet},
|
||||
};
|
||||
@@ -31,6 +32,16 @@ impl<T> PathMap<T> {
|
||||
self.nodes.get(path).map(|v| &v.value)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, path: &Path) -> Option<&mut T> {
|
||||
self.nodes.get_mut(path).map(|v| &mut v.value)
|
||||
}
|
||||
|
||||
pub fn entry<'a>(&'a mut self, path: PathBuf) -> Entry<'a, T> {
|
||||
Entry {
|
||||
internal: self.nodes.entry(path),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, path: PathBuf, value: T) {
|
||||
if let Some(parent_path) = path.parent() {
|
||||
if let Some(parent) = self.nodes.get_mut(parent_path) {
|
||||
@@ -105,4 +116,28 @@ impl<T> PathMap<T> {
|
||||
|
||||
current_path
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Entry<'a, T> {
|
||||
internal: hash_map::Entry<'a, PathBuf, PathMapNode<T>>,
|
||||
}
|
||||
|
||||
impl<'a, T> Entry<'a, T> {
|
||||
pub fn or_insert(self, value: T) -> &'a mut T {
|
||||
&mut self.internal.or_insert(PathMapNode {
|
||||
value,
|
||||
children: HashSet::new(),
|
||||
}).value
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Entry<'a, T>
|
||||
where T: Default
|
||||
{
|
||||
pub fn or_default(self) -> &'a mut T {
|
||||
&mut self.internal.or_insert(PathMapNode {
|
||||
value: Default::default(),
|
||||
children: HashSet::new(),
|
||||
}).value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user