forked from rojo-rbx/rojo
Get rid of confusing 'SnapshotInstanceResult' type alias
This commit is contained in:
@@ -7,14 +7,14 @@ use serde::Serialize;
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::{meta_file::AdjacentMetadata, middleware::SnapshotInstanceResult};
|
||||
use super::meta_file::AdjacentMetadata;
|
||||
|
||||
pub fn snapshot_csv(
|
||||
_context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let meta_path = path.with_file_name(format!("{}.meta.json", instance_name));
|
||||
let contents = vfs.read(path)?;
|
||||
|
||||
|
||||
@@ -4,9 +4,13 @@ use memofs::{DirEntry, IoResultExt, Vfs};
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::{meta_file::DirectoryMetadata, middleware::SnapshotInstanceResult, snapshot_from_vfs};
|
||||
use super::{meta_file::DirectoryMetadata, snapshot_from_vfs};
|
||||
|
||||
pub fn snapshot_dir(context: &InstanceContext, vfs: &Vfs, path: &Path) -> SnapshotInstanceResult {
|
||||
pub fn snapshot_dir(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let passes_filter_rules = |child: &DirEntry| {
|
||||
context
|
||||
.path_ignore_rules
|
||||
|
||||
@@ -9,14 +9,14 @@ use crate::{
|
||||
snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot},
|
||||
};
|
||||
|
||||
use super::{meta_file::AdjacentMetadata, middleware::SnapshotInstanceResult};
|
||||
use super::meta_file::AdjacentMetadata;
|
||||
|
||||
pub fn snapshot_json(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let contents = vfs.read(path)?;
|
||||
|
||||
let value: serde_json::Value = serde_json::from_slice(&contents)
|
||||
|
||||
@@ -9,14 +9,12 @@ use crate::{
|
||||
snapshot::{InstanceContext, InstanceSnapshot},
|
||||
};
|
||||
|
||||
use super::middleware::SnapshotInstanceResult;
|
||||
|
||||
pub fn snapshot_json_model(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let contents = vfs.read(path)?;
|
||||
let contents_str = str::from_utf8(&contents)
|
||||
.with_context(|| format!("File was not valid UTF-8: {}", path.display()))?;
|
||||
|
||||
@@ -6,13 +6,14 @@ use memofs::{IoResultExt, Vfs};
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::{
|
||||
dir::snapshot_dir, meta_file::AdjacentMetadata, middleware::SnapshotInstanceResult,
|
||||
util::match_trailing,
|
||||
};
|
||||
use super::{dir::snapshot_dir, meta_file::AdjacentMetadata, util::match_trailing};
|
||||
|
||||
/// Core routine for turning Lua files into snapshots.
|
||||
pub fn snapshot_lua(context: &InstanceContext, vfs: &Vfs, path: &Path) -> SnapshotInstanceResult {
|
||||
pub fn snapshot_lua(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let file_name = path.file_name().unwrap().to_string_lossy();
|
||||
|
||||
let (class_name, instance_name) = if let Some(name) = match_trailing(&file_name, ".server.lua")
|
||||
@@ -63,7 +64,7 @@ pub fn snapshot_lua_init(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
init_path: &Path,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let folder_path = init_path.parent().unwrap();
|
||||
let dir_snapshot = snapshot_dir(context, vfs, folder_path)?.unwrap();
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
use crate::snapshot::InstanceSnapshot;
|
||||
|
||||
pub type SnapshotInstanceResult = anyhow::Result<Option<InstanceSnapshot>>;
|
||||
@@ -11,7 +11,6 @@ mod json;
|
||||
mod json_model;
|
||||
mod lua;
|
||||
mod meta_file;
|
||||
mod middleware;
|
||||
mod project;
|
||||
mod rbxm;
|
||||
mod rbxmx;
|
||||
@@ -22,7 +21,7 @@ use std::path::Path;
|
||||
|
||||
use memofs::{IoResultExt, Vfs};
|
||||
|
||||
use crate::snapshot::InstanceContext;
|
||||
use crate::snapshot::{InstanceContext, InstanceSnapshot};
|
||||
|
||||
use self::{
|
||||
csv::snapshot_csv,
|
||||
@@ -30,7 +29,6 @@ use self::{
|
||||
json::snapshot_json,
|
||||
json_model::snapshot_json_model,
|
||||
lua::{snapshot_lua, snapshot_lua_init},
|
||||
middleware::SnapshotInstanceResult,
|
||||
project::snapshot_project,
|
||||
rbxm::snapshot_rbxm,
|
||||
rbxmx::snapshot_rbxmx,
|
||||
@@ -46,7 +44,7 @@ pub fn snapshot_from_vfs(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let meta = match vfs.metadata(path).with_not_found()? {
|
||||
Some(meta) => meta,
|
||||
None => return Ok(None),
|
||||
|
||||
@@ -11,13 +11,13 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
use super::{middleware::SnapshotInstanceResult, snapshot_from_vfs};
|
||||
use super::snapshot_from_vfs;
|
||||
|
||||
pub fn snapshot_project(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let project = Project::load_from_slice(&vfs.read(path)?, path)
|
||||
.with_context(|| format!("File was not a valid Rojo project: {}", path.display()))?;
|
||||
|
||||
@@ -63,7 +63,7 @@ pub fn snapshot_project_node(
|
||||
node: &ProjectNode,
|
||||
vfs: &Vfs,
|
||||
parent_class: Option<&str>,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let project_folder = project_path.parent().unwrap();
|
||||
|
||||
let class_name_from_project = node
|
||||
|
||||
@@ -5,14 +5,12 @@ use memofs::Vfs;
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::middleware::SnapshotInstanceResult;
|
||||
|
||||
pub fn snapshot_rbxm(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let temp_tree = rbx_binary::from_reader(vfs.read(path)?.as_slice())
|
||||
.with_context(|| format!("Malformed rbxm file: {}", path.display()))?;
|
||||
|
||||
|
||||
@@ -5,14 +5,12 @@ use memofs::Vfs;
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::middleware::SnapshotInstanceResult;
|
||||
|
||||
pub fn snapshot_rbxmx(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let options = rbx_xml::DecodeOptions::new()
|
||||
.property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown);
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ use memofs::{IoResultExt, Vfs};
|
||||
|
||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||
|
||||
use super::{meta_file::AdjacentMetadata, middleware::SnapshotInstanceResult};
|
||||
use super::meta_file::AdjacentMetadata;
|
||||
|
||||
pub fn snapshot_txt(
|
||||
context: &InstanceContext,
|
||||
vfs: &Vfs,
|
||||
path: &Path,
|
||||
instance_name: &str,
|
||||
) -> SnapshotInstanceResult {
|
||||
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||
let contents = vfs.read(path)?;
|
||||
let contents_str = str::from_utf8(&contents)
|
||||
.with_context(|| format!("File was not valid UTF-8: {}", path.display()))?
|
||||
|
||||
Reference in New Issue
Block a user