Make SnapshotMiddleware::from_instance have a default impl

This commit is contained in:
Lucien Greathouse
2019-10-10 10:43:55 -07:00
parent e46f9fd94f
commit 6d38a785ed
8 changed files with 14 additions and 53 deletions

View File

@@ -1,7 +1,7 @@
use std::{borrow::Cow, collections::BTreeMap};
use maplit::hashmap;
use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
use rbx_dom_weak::RbxValue;
use serde::Serialize;
use crate::{
@@ -11,7 +11,7 @@ use crate::{
use super::{
meta_file::AdjacentMetadata,
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_file_name,
};
@@ -62,10 +62,6 @@ impl SnapshotMiddleware for SnapshotCsv {
Ok(Some(snapshot))
}
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
unimplemented!("Snapshotting CSV localization tables");
}
}
/// Struct that holds any valid row from a Roblox CSV translation table.

View File

@@ -1,6 +1,6 @@
use std::{borrow::Cow, collections::HashMap};
use rbx_dom_weak::{RbxId, RbxTree, UnresolvedRbxValue};
use rbx_dom_weak::UnresolvedRbxValue;
use rbx_reflection::try_resolve_value;
use serde::Deserialize;
@@ -10,7 +10,7 @@ use crate::{
};
use super::{
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_file_name,
};
@@ -58,10 +58,6 @@ impl SnapshotMiddleware for SnapshotJsonModel {
Ok(Some(snapshot))
}
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
unimplemented!("Snapshotting models");
}
}
fn match_trailing<'a>(input: &'a str, trailer: &str) -> Option<&'a str> {

View File

@@ -1,7 +1,7 @@
use std::{borrow::Cow, str};
use maplit::hashmap;
use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
use rbx_dom_weak::RbxValue;
use crate::{
imfs::{FsResultExt, Imfs, ImfsEntry, ImfsFetcher},
@@ -11,7 +11,7 @@ use crate::{
use super::{
dir::SnapshotDir,
meta_file::AdjacentMetadata,
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_trailing,
};
@@ -48,17 +48,6 @@ impl SnapshotMiddleware for SnapshotLua {
}
}
}
fn from_instance(tree: &RbxTree, id: RbxId) -> SnapshotFileResult {
let instance = tree.get_instance(id).unwrap();
match instance.class_name.as_str() {
"ModuleScript" | "LocalScript" | "Script" => {
unimplemented!("Snapshotting Script instances")
}
_ => None,
}
}
}
/// Core routine for turning Lua files into snapshots.

View File

@@ -18,7 +18,9 @@ pub trait SnapshotMiddleware {
entry: &ImfsEntry,
) -> SnapshotInstanceResult<'static>;
fn from_instance(tree: &RbxTree, id: RbxId) -> SnapshotFileResult;
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
None
}
fn change_affects_paths(path: &Path) -> Vec<PathBuf> {
vec![path.to_path_buf()]

View File

@@ -1,6 +1,5 @@
use std::{borrow::Cow, collections::HashMap};
use rbx_dom_weak::{RbxId, RbxTree};
use rbx_reflection::try_resolve_value;
use crate::{
@@ -11,7 +10,7 @@ use crate::{
use super::{
error::SnapshotError,
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
snapshot_from_imfs,
};
@@ -72,11 +71,6 @@ impl SnapshotMiddleware for SnapshotProject {
Ok(Some(snapshot))
}
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
// TODO: Supporting turning instances into projects
None
}
}
fn snapshot_project_node<F: ImfsFetcher>(

View File

@@ -1,14 +1,12 @@
use std::borrow::Cow;
use rbx_dom_weak::{RbxId, RbxTree};
use crate::{
imfs::{Imfs, ImfsEntry, ImfsFetcher},
snapshot::InstanceSnapshot,
};
use super::{
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_file_name,
};
@@ -43,8 +41,4 @@ impl SnapshotMiddleware for SnapshotRbxlx {
Ok(Some(snapshot))
}
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
None
}
}

View File

@@ -1,6 +1,6 @@
use std::{borrow::Cow, collections::HashMap};
use rbx_dom_weak::{RbxId, RbxInstanceProperties, RbxTree};
use rbx_dom_weak::{RbxInstanceProperties, RbxTree};
use crate::{
imfs::{Imfs, ImfsEntry, ImfsFetcher},
@@ -8,7 +8,7 @@ use crate::{
};
use super::{
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_file_name,
};
@@ -52,10 +52,6 @@ impl SnapshotMiddleware for SnapshotRbxm {
panic!("Rojo doesn't have support for model files with zero or more than one top-level instances yet.");
}
}
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
unimplemented!("Snapshotting models");
}
}
#[cfg(test)]

View File

@@ -1,14 +1,12 @@
use std::borrow::Cow;
use rbx_dom_weak::{RbxId, RbxTree};
use crate::{
imfs::{Imfs, ImfsEntry, ImfsFetcher},
snapshot::InstanceSnapshot,
};
use super::{
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_file_name,
};
@@ -48,10 +46,6 @@ impl SnapshotMiddleware for SnapshotRbxmx {
panic!("Rojo doesn't have support for model files with zero or more than one top-level instances yet.");
}
}
fn from_instance(_tree: &RbxTree, _id: RbxId) -> SnapshotFileResult {
unimplemented!("Snapshotting models");
}
}
#[cfg(test)]