mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Start stripping out lifetimes in InstanceSnapshot
This commit is contained in:
@@ -7,15 +7,13 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::InstanceMetadata;
|
||||
|
||||
/// A lightweight description of what an instance should look like. Attempts to
|
||||
/// be somewhat memory efficient by borrowing from its source data, indicated by
|
||||
/// the lifetime parameter `'source`.
|
||||
/// A lightweight description of what an instance should look like.
|
||||
///
|
||||
// Possible future improvements:
|
||||
// - Use refcounted/interned strings
|
||||
// - Replace use of RbxValue with a sum of RbxValue + borrowed value
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct InstanceSnapshot<'source> {
|
||||
pub struct InstanceSnapshot {
|
||||
/// A temporary ID applied to the snapshot that's used for Ref properties.
|
||||
pub snapshot_id: Option<RbxId>,
|
||||
|
||||
@@ -23,10 +21,10 @@ pub struct InstanceSnapshot<'source> {
|
||||
pub metadata: InstanceMetadata,
|
||||
|
||||
/// Correpsonds to the Name property of the instance.
|
||||
pub name: Cow<'source, str>,
|
||||
pub name: Cow<'static, str>,
|
||||
|
||||
/// Corresponds to the ClassName property of the instance.
|
||||
pub class_name: Cow<'source, str>,
|
||||
pub class_name: Cow<'static, str>,
|
||||
|
||||
/// All other properties of the instance, weakly-typed.
|
||||
pub properties: HashMap<String, RbxValue>,
|
||||
@@ -34,11 +32,11 @@ pub struct InstanceSnapshot<'source> {
|
||||
/// The children of the instance represented as more snapshots.
|
||||
///
|
||||
/// Order is relevant for Roblox instances!
|
||||
pub children: Vec<InstanceSnapshot<'source>>,
|
||||
pub children: Vec<InstanceSnapshot>,
|
||||
}
|
||||
|
||||
impl<'source> InstanceSnapshot<'source> {
|
||||
pub fn from_tree(tree: &RbxTree, id: RbxId) -> InstanceSnapshot<'static> {
|
||||
impl InstanceSnapshot {
|
||||
pub fn from_tree(tree: &RbxTree, id: RbxId) -> InstanceSnapshot {
|
||||
let instance = tree
|
||||
.get_instance(id)
|
||||
.expect("instance did not exist in tree");
|
||||
@@ -61,8 +59,8 @@ impl<'source> InstanceSnapshot<'source> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'source> Default for InstanceSnapshot<'source> {
|
||||
fn default() -> InstanceSnapshot<'source> {
|
||||
impl Default for InstanceSnapshot {
|
||||
fn default() -> InstanceSnapshot {
|
||||
InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
metadata: InstanceMetadata::default(),
|
||||
|
||||
@@ -13,13 +13,13 @@ use super::{InstanceMetadata, InstanceSnapshot};
|
||||
/// sure that another patch wasn't applied before this one that could cause a
|
||||
/// conflict!
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PatchSet<'a> {
|
||||
pub struct PatchSet {
|
||||
pub removed_instances: Vec<RbxId>,
|
||||
pub added_instances: Vec<PatchAdd<'a>>,
|
||||
pub added_instances: Vec<PatchAdd>,
|
||||
pub updated_instances: Vec<PatchUpdate>,
|
||||
}
|
||||
|
||||
impl<'a> PatchSet<'a> {
|
||||
impl<'a> PatchSet {
|
||||
pub fn new() -> Self {
|
||||
PatchSet {
|
||||
removed_instances: Vec::new(),
|
||||
@@ -31,9 +31,9 @@ impl<'a> PatchSet<'a> {
|
||||
|
||||
/// A patch containing an instance that was added to the tree.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PatchAdd<'a> {
|
||||
pub struct PatchAdd {
|
||||
pub parent_id: RbxId,
|
||||
pub instance: InstanceSnapshot<'a>,
|
||||
pub instance: InstanceSnapshot,
|
||||
}
|
||||
|
||||
/// A patch indicating that properties of an instance changed.
|
||||
|
||||
@@ -10,11 +10,7 @@ use super::{
|
||||
InstanceSnapshot, InstanceWithMeta, RojoTree,
|
||||
};
|
||||
|
||||
pub fn compute_patch_set<'a>(
|
||||
snapshot: &'a InstanceSnapshot,
|
||||
tree: &RojoTree,
|
||||
id: RbxId,
|
||||
) -> PatchSet<'a> {
|
||||
pub fn compute_patch_set(snapshot: &InstanceSnapshot, tree: &RojoTree, id: RbxId) -> PatchSet {
|
||||
let mut patch_set = PatchSet::new();
|
||||
let mut context = ComputePatchContext::default();
|
||||
|
||||
@@ -69,12 +65,12 @@ fn rewrite_refs_in_snapshot(context: &ComputePatchContext, snapshot: &mut Instan
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_patch_set_internal<'a>(
|
||||
fn compute_patch_set_internal(
|
||||
context: &mut ComputePatchContext,
|
||||
snapshot: &'a InstanceSnapshot,
|
||||
snapshot: &InstanceSnapshot,
|
||||
tree: &RojoTree,
|
||||
id: RbxId,
|
||||
patch_set: &mut PatchSet<'a>,
|
||||
patch_set: &mut PatchSet,
|
||||
) {
|
||||
if let Some(snapshot_id) = snapshot.snapshot_id {
|
||||
context.snapshot_id_to_instance_id.insert(snapshot_id, id);
|
||||
@@ -154,12 +150,12 @@ fn compute_property_patches(
|
||||
});
|
||||
}
|
||||
|
||||
fn compute_children_patches<'a>(
|
||||
fn compute_children_patches(
|
||||
context: &mut ComputePatchContext,
|
||||
snapshot: &'a InstanceSnapshot,
|
||||
snapshot: &InstanceSnapshot,
|
||||
tree: &RojoTree,
|
||||
id: RbxId,
|
||||
patch_set: &mut PatchSet<'a>,
|
||||
patch_set: &mut PatchSet,
|
||||
) {
|
||||
let instance = tree
|
||||
.get_instance(id)
|
||||
|
||||
@@ -102,7 +102,7 @@ struct JsonModelCore {
|
||||
}
|
||||
|
||||
impl JsonModelCore {
|
||||
fn into_snapshot(self, name: String) -> InstanceSnapshot<'static> {
|
||||
fn into_snapshot(self, name: String) -> InstanceSnapshot {
|
||||
let class_name = self.class_name;
|
||||
|
||||
let children = self
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
|
||||
use super::{context::InstanceSnapshotContext, error::SnapshotError};
|
||||
|
||||
pub type SnapshotInstanceResult<'a> = Result<Option<InstanceSnapshot<'a>>, SnapshotError>;
|
||||
pub type SnapshotInstanceResult<'a> = Result<Option<InstanceSnapshot>, SnapshotError>;
|
||||
pub type SnapshotFileResult = Option<(String, VfsSnapshot)>;
|
||||
|
||||
pub trait SnapshotMiddleware {
|
||||
|
||||
Reference in New Issue
Block a user