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