diff --git a/crates/fj-core/src/objects/any_object.rs b/crates/fj-core/src/objects/any_object.rs index e290bf9b5..f0f6973ec 100644 --- a/crates/fj-core/src/objects/any_object.rs +++ b/crates/fj-core/src/objects/any_object.rs @@ -9,11 +9,12 @@ use crate::{ macro_rules! any_object { ($($ty:ident, $name:expr, $store:ident;)*) => { - /// An enum that can hold object + /// An enum that can hold any object /// /// This enum is generic over the form that the object takes. An - /// `AnyObject` contains bare objects, like `Curve`. An - /// `AnyObject` contains handles, like `Handle`. + /// `AnyObject` contains a bare objects, for example `Curve`. An + /// `AnyObject` contains a handle referencing a stored object, + /// for example `Handle`. #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub enum AnyObject { $( @@ -22,7 +23,7 @@ macro_rules! any_object { )* } - impl AnyObject { + impl AnyObject { /// Access the ID of the object pub fn id(&self) -> ObjectId { match self { @@ -42,7 +43,10 @@ macro_rules! any_object { } /// Validate the object with a pre-defined validation configuration - pub fn validate_with_config(&self, config: &ValidationConfig, errors: &mut Vec) { + pub fn validate_with_config(&self, + config: &ValidationConfig, + errors: &mut Vec + ) { match self { $( Self::$ty(object) => object.validate_with_config(config, errors), @@ -51,11 +55,9 @@ macro_rules! any_object { } } - impl AnyObject { + impl AnyObject { /// Insert the object into its respective store - pub fn insert(self, objects: &mut Objects) -> - AnyObject - { + pub fn insert(self, objects: &mut Objects) -> AnyObject { match self { $( Self::$ty((handle, object)) => { @@ -69,8 +71,8 @@ macro_rules! any_object { } } - impl From> for AnyObject { - fn from(object: AnyObject) -> Self { + impl From> for AnyObject { + fn from(object: AnyObject) -> Self { match object { $( AnyObject::$ty((handle, _)) => Self::$ty(handle.into()), @@ -86,13 +88,13 @@ macro_rules! any_object { } } - impl From> for AnyObject { + impl From> for AnyObject { fn from(object: Handle<$ty>) -> Self { Self::$ty(object.into()) } } - impl From<(Handle<$ty>, $ty)> for AnyObject { + impl From<(Handle<$ty>, $ty)> for AnyObject { fn from((handle, object): (Handle<$ty>, $ty)) -> Self { Self::$ty((handle.into(), object)) } @@ -116,8 +118,10 @@ any_object!( /// The form that an object can take /// -/// An object can be bare ([`Bare`]), behind a [`Handle`] ([`BehindHandle`]), or -/// can take the form of a handle *and* an object [`WithHandle`]. +/// This is used together with [`AnyObject`]. +/// +/// An object can be bare ([`Bare`]), stored ([`Stored`]), or it can be about to +/// be - but not yet - stored ([`AboutToBeStored`]). pub trait Form { /// The form that the object takes type Form; @@ -131,18 +135,24 @@ impl Form for Bare { type Form = T; } -/// Implementation of [`Form`] for objects behind a handle +/// Implementation of [`Form`] for stored objects #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] -pub struct BehindHandle; +pub struct Stored; -impl Form for BehindHandle { +impl Form for Stored { type Form = HandleWrapper; } -/// Implementation of [`Form`] for objects that are paired with their handle +/// Implementation of [`Form`] for objects that are about to be stored +/// +/// When storing an object, a [`Handle`] instance is generated first. Then both +/// that [`Handle`] instance and the bare object are sent to the object service, +/// for storage. +/// +/// This is the one use case where this form is required. #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] -pub struct WithHandle; +pub struct AboutToBeStored; -impl Form for WithHandle { +impl Form for AboutToBeStored { type Form = (HandleWrapper, T); } diff --git a/crates/fj-core/src/objects/mod.rs b/crates/fj-core/src/objects/mod.rs index d16880683..db4110aee 100644 --- a/crates/fj-core/src/objects/mod.rs +++ b/crates/fj-core/src/objects/mod.rs @@ -46,7 +46,7 @@ mod object_set; mod stores; pub use self::{ - any_object::{AnyObject, Bare, BehindHandle, Form, WithHandle}, + any_object::{AboutToBeStored, AnyObject, Bare, Form, Stored}, is_object::IsObject, kinds::{ curve::Curve, diff --git a/crates/fj-core/src/services/mod.rs b/crates/fj-core/src/services/mod.rs index 8cab4b943..7e7842247 100644 --- a/crates/fj-core/src/services/mod.rs +++ b/crates/fj-core/src/services/mod.rs @@ -7,7 +7,7 @@ mod service; mod validation; use crate::{ - objects::{AnyObject, Objects, WithHandle}, + objects::{AboutToBeStored, AnyObject, Objects}, validate::{ValidationConfig, ValidationErrors}, }; @@ -54,7 +54,7 @@ impl Services { } /// Insert an object into the stores - pub fn insert_object(&mut self, object: AnyObject) { + pub fn insert_object(&mut self, object: AnyObject) { let mut object_events = Vec::new(); self.objects .execute(Operation::InsertObject { object }, &mut object_events); diff --git a/crates/fj-core/src/services/objects.rs b/crates/fj-core/src/services/objects.rs index 924444ad5..745432627 100644 --- a/crates/fj-core/src/services/objects.rs +++ b/crates/fj-core/src/services/objects.rs @@ -1,4 +1,4 @@ -use crate::objects::{AnyObject, Objects, WithHandle}; +use crate::objects::{AboutToBeStored, AnyObject, Objects}; use super::State; @@ -25,7 +25,7 @@ pub enum Operation { /// upon. InsertObject { /// The object to insert - object: AnyObject, + object: AnyObject, }, } @@ -33,5 +33,5 @@ pub enum Operation { #[derive(Clone, Debug)] pub struct InsertObject { /// The object to insert - pub object: AnyObject, + pub object: AnyObject, } diff --git a/crates/fj-core/src/services/validation.rs b/crates/fj-core/src/services/validation.rs index b3860e25f..66b916761 100644 --- a/crates/fj-core/src/services/validation.rs +++ b/crates/fj-core/src/services/validation.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, error::Error, thread}; use crate::{ - objects::{AnyObject, BehindHandle}, + objects::{AnyObject, Stored}, storage::ObjectId, validate::{ValidationConfig, ValidationError}, }; @@ -97,7 +97,7 @@ pub enum ValidationCommand { /// Validate the provided object ValidateObject { /// The object to validate - object: AnyObject, + object: AnyObject, }, } @@ -107,7 +107,7 @@ pub enum ValidationEvent { /// Validation of an object failed ValidationFailed { /// The object for which validation failed - object: AnyObject, + object: AnyObject, /// The validation error err: ValidationError,