From e4a6aa96b49aeec35732e9c40ac0ef839da546f0 Mon Sep 17 00:00:00 2001 From: "Keith T. Star" Date: Wed, 29 Nov 2023 06:48:45 -0700 Subject: [PATCH] deeper down that darn hole we journey --- Cargo.toml | 10 +- sarzak.toml | 25 +- src/lib.rs | 13 +- src/v2.rs | 1 + src/v2/domain.rs | 8 +- src/v2/drawing/types/binary_ui.rs | 11 +- src/v2/merlin/from.rs | 156 +- src/v2/merlin/types/line.rs | 9 +- src/v2/sarzak_single/from.rs | 193 +- src/v2/sarzak_single/store.rs | 1144 +++----- .../sarzak_single/types/acknowledged_event.rs | 20 +- .../types/an_associative_referent.rs | 23 +- src/v2/sarzak_single/types/associative.rs | 25 +- .../types/associative_referent.rs | 36 +- .../types/associative_referrer.rs | 30 +- src/v2/sarzak_single/types/attribute.rs | 21 +- src/v2/sarzak_single/types/binary.rs | 25 +- src/v2/sarzak_single/types/cardinality.rs | 30 +- src/v2/sarzak_single/types/conditionality.rs | 28 +- src/v2/sarzak_single/types/event.rs | 20 +- src/v2/sarzak_single/types/external.rs | 10 +- src/v2/sarzak_single/types/isa.rs | 28 +- src/v2/sarzak_single/types/object.rs | 49 +- src/v2/sarzak_single/types/referent.rs | 36 +- src/v2/sarzak_single/types/referrer.rs | 36 +- src/v2/sarzak_single/types/relationship.rs | 47 +- src/v2/sarzak_single/types/state.rs | 20 +- src/v2/sarzak_single/types/subtype.rs | 20 +- src/v2/sarzak_single/types/supertype.rs | 19 +- src/v2/sarzak_single/types/ty.rs | 68 +- src/v2/woog_single.rs | 13 + src/v2/woog_single/store.rs | 2474 +++++++++++++++++ src/v2/woog_single/types.rs | 95 + src/v2/woog_single/types/access.rs | 71 + src/v2/woog_single/types/block.rs | 77 + src/v2/woog_single/types/borrowed.rs | 37 + src/v2/woog_single/types/call.rs | 55 + src/v2/woog_single/types/constant.rs | 43 + src/v2/woog_single/types/enumeration.rs | 58 + src/v2/woog_single/types/enumeration_field.rs | 59 + src/v2/woog_single/types/expression.rs | 91 + .../woog_single/types/expression_statement.rs | 39 + src/v2/woog_single/types/field.rs | 79 + src/v2/woog_single/types/function.rs | 75 + src/v2/woog_single/types/generation_unit.rs | 56 + src/v2/woog_single/types/grace_type.rs | 113 + src/v2/woog_single/types/implementation.rs | 35 + src/v2/woog_single/types/item.rs | 99 + src/v2/woog_single/types/krate.rs | 37 + src/v2/woog_single/types/literal.rs | 35 + src/v2/woog_single/types/local.rs | 55 + src/v2/woog_single/types/mutable.rs | 37 + src/v2/woog_single/types/object_method.rs | 95 + src/v2/woog_single/types/owned.rs | 35 + src/v2/woog_single/types/ownership.rs | 69 + src/v2/woog_single/types/parameter.rs | 98 + src/v2/woog_single/types/private.rs | 35 + src/v2/woog_single/types/public.rs | 35 + src/v2/woog_single/types/reference.rs | 57 + src/v2/woog_single/types/statement.rs | 102 + src/v2/woog_single/types/structure.rs | 53 + src/v2/woog_single/types/structure_field.rs | 84 + src/v2/woog_single/types/symbol_table.rs | 57 + src/v2/woog_single/types/time_stamp.rs | 39 + src/v2/woog_single/types/usize.rs | 33 + src/v2/woog_single/types/variable.rs | 111 + src/v2/woog_single/types/visibility.rs | 73 + src/v2/woog_single/types/woog_option.rs | 50 + src/v2/woog_single/types/x_let.rs | 83 + src/v2/woog_single/types/x_macro.rs | 36 + src/v2/woog_single/types/x_value.rs | 101 + 71 files changed, 5907 insertions(+), 1233 deletions(-) create mode 100644 src/v2/woog_single.rs create mode 100644 src/v2/woog_single/store.rs create mode 100644 src/v2/woog_single/types.rs create mode 100644 src/v2/woog_single/types/access.rs create mode 100644 src/v2/woog_single/types/block.rs create mode 100644 src/v2/woog_single/types/borrowed.rs create mode 100644 src/v2/woog_single/types/call.rs create mode 100644 src/v2/woog_single/types/constant.rs create mode 100644 src/v2/woog_single/types/enumeration.rs create mode 100644 src/v2/woog_single/types/enumeration_field.rs create mode 100644 src/v2/woog_single/types/expression.rs create mode 100644 src/v2/woog_single/types/expression_statement.rs create mode 100644 src/v2/woog_single/types/field.rs create mode 100644 src/v2/woog_single/types/function.rs create mode 100644 src/v2/woog_single/types/generation_unit.rs create mode 100644 src/v2/woog_single/types/grace_type.rs create mode 100644 src/v2/woog_single/types/implementation.rs create mode 100644 src/v2/woog_single/types/item.rs create mode 100644 src/v2/woog_single/types/krate.rs create mode 100644 src/v2/woog_single/types/literal.rs create mode 100644 src/v2/woog_single/types/local.rs create mode 100644 src/v2/woog_single/types/mutable.rs create mode 100644 src/v2/woog_single/types/object_method.rs create mode 100644 src/v2/woog_single/types/owned.rs create mode 100644 src/v2/woog_single/types/ownership.rs create mode 100644 src/v2/woog_single/types/parameter.rs create mode 100644 src/v2/woog_single/types/private.rs create mode 100644 src/v2/woog_single/types/public.rs create mode 100644 src/v2/woog_single/types/reference.rs create mode 100644 src/v2/woog_single/types/statement.rs create mode 100644 src/v2/woog_single/types/structure.rs create mode 100644 src/v2/woog_single/types/structure_field.rs create mode 100644 src/v2/woog_single/types/symbol_table.rs create mode 100644 src/v2/woog_single/types/time_stamp.rs create mode 100644 src/v2/woog_single/types/usize.rs create mode 100644 src/v2/woog_single/types/variable.rs create mode 100644 src/v2/woog_single/types/visibility.rs create mode 100644 src/v2/woog_single/types/woog_option.rs create mode 100644 src/v2/woog_single/types/x_let.rs create mode 100644 src/v2/woog_single/types/x_macro.rs create mode 100644 src/v2/woog_single/types/x_value.rs diff --git a/Cargo.toml b/Cargo.toml index b9685bb3..455e1bbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sarzak" -version = "2.8.0" +version = "2.11.0" edition = "2021" authors = ["Keith T. Star "] categories = ["compilers", "memory-management"] @@ -52,7 +52,7 @@ env_logger = "0.10.0" pretty_env_logger = "0.5.0" [features] -default = ["lu-dog-vec", "sarzak_single"] +default = ["lu-dog-vec", "sarzak-rwlock"] lu-dog-vec = [] lu-dog-vec-tracy = [] lu-dog-rwlock-vec = [] @@ -60,5 +60,7 @@ lu-dog-ndrwlock-vec = [] lu-dog-rc = [] lu-dog-rwlock = [] lu-dog-async-vec = [] -sarzak_single = [] -sarzak_rwlock = [] +sarzak-single = [] +sarzak-rwlock = [] +woog-single = [] +woog-rwLock = [] diff --git a/sarzak.toml b/sarzak.toml index 34591353..46e9739b 100644 --- a/sarzak.toml +++ b/sarzak.toml @@ -298,7 +298,7 @@ is_meta_model = true is_sarzak = true persist = true persist_timestamps = true -uber_store = "Single" +uber_store = "Disabled" target = "domain" # @@ -323,3 +323,26 @@ persist = true persist_timestamps = true uber_store = "StdRwLock" target = "domain" + +# +# Woog Single +# +[modules."v2/woog_single"] +model = "models/woog.json" + +[[modules."v2/woog_single".compiler]] +always_process = true +compiler = "grace" +derive = ["Clone", "Debug", "Deserialize", "PartialEq", "Serialize"] +imported_domains = ["crate/v2/sarzak"] +use_paths = ["serde::{Deserialize, Serialize}"] +tracy = false + +[modules."v2/woog_single".compiler.target] +optimization_level = "None" +is_meta_model = true +is_sarzak = false +persist = true +persist_timestamps = true +uber_store = "Disabled" +target = "domain" diff --git a/src/lib.rs b/src/lib.rs index 086cecaa..642a44da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,16 +10,23 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub use v2::drawing; pub use v2::merlin; -pub use v2::woog; cfg_if::cfg_if! { - if #[cfg(feature = "sarzak_rwlock")] { + if #[cfg(feature = "sarzak-rwlock")] { pub use v2::sarzak; - } else if #[cfg(feature = "sarzak_single")] { + } else if #[cfg(feature = "sarzak-single")] { pub use v2::sarzak_single as sarzak; } } +cfg_if::cfg_if! { + if #[cfg(feature = "woog-rwlock")] { + pub use v2::woog; + } else if #[cfg(feature = "woog-single")] { + pub use v2::woog_single as woog; + } +} + cfg_if::cfg_if! { if #[cfg(feature = "lu-dog-rc")] { pub use v2::lu_dog; diff --git a/src/v2.rs b/src/v2.rs index 547fa33a..4392c5a8 100644 --- a/src/v2.rs +++ b/src/v2.rs @@ -11,3 +11,4 @@ pub mod merlin; pub mod sarzak; pub mod sarzak_single; pub mod woog; +pub mod woog_single; diff --git a/src/v2/domain.rs b/src/v2/domain.rs index 8d64bfb3..f00e5383 100644 --- a/src/v2/domain.rs +++ b/src/v2/domain.rs @@ -9,8 +9,14 @@ use uuid::Uuid; use crate::v1::domain::Domain as DomainV1; use crate::v2::{ drawing::store::ObjectStore as DrawingStore, merlin::store::ObjectStore as MerlinStore, - sarzak::store::ObjectStore as SarzakStore, }; + +#[cfg(feature = "sarzak_multi")] +use crate::v2::sarzak::store::ObjectStore as SarzakStore; + +#[cfg(feature = "sarzak_single")] +use crate::v2::sarzak_single::store::ObjectStore as SarzakStore; + use crate::VERSION; #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/src/v2/drawing/types/binary_ui.rs b/src/v2/drawing/types/binary_ui.rs index 8a79a2b6..bda12212 100644 --- a/src/v2/drawing/types/binary_ui.rs +++ b/src/v2/drawing/types/binary_ui.rs @@ -6,11 +6,17 @@ use uuid::Uuid; use crate::v2::drawing::types::anchor::Anchor; use crate::v2::drawing::types::relationship_ui::RelationshipUi; +#[cfg(feature = "sarzak_multi")] use crate::v2::sarzak::types::binary::Binary; +#[cfg(feature = "sarzak_single")] +use crate::v2::sarzak_single::types::binary::Binary; use serde::{Deserialize, Serialize}; use crate::v2::drawing::store::ObjectStore as DrawingStore; +#[cfg(feature = "sarzak_multi")] use crate::v2::sarzak::store::ObjectStore as SarzakStore; +#[cfg(feature = "sarzak_single")] +use crate::v2::sarzak_single::store::ObjectStore as SarzakStore; // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary_ui-struct-documentation"}}} @@ -57,10 +63,7 @@ impl BinaryUi { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary_ui-struct-impl-nav-forward-to-to"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary_ui-struct-impl-nav-forward-to-binary_id"}}} /// Navigate to [`Binary`] across R12(1-*) - pub fn r12_binary<'a>( - &'a self, - store: &'a SarzakStore, - ) -> Vec>> { + pub fn r12_binary<'a>(&'a self, store: &'a SarzakStore) -> Vec<&Binary> { vec![store.exhume_binary(&self.binary_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/merlin/from.rs b/src/v2/merlin/from.rs index cf7e47dd..66483719 100644 --- a/src/v2/merlin/from.rs +++ b/src/v2/merlin/from.rs @@ -21,8 +21,10 @@ use crate::v2::merlin::ObjectStore; use crate::v2::drawing::types::{Edge as FromEdge, ObjectUi, Point as FromPoint}; use crate::v2::drawing::ObjectStore as DrawingStore; -use crate::v2::sarzak::types::Cardinality; -use crate::v2::sarzak::ObjectStore as SarzakStore; +#[cfg(feature = "sarzak_multi")] +use crate::v2::sarzak::{types::Cardinality, ObjectStore as SarzakStore}; +#[cfg(feature = "sarzak_single")] +use crate::v2::sarzak_single::{types::Cardinality, ObjectStore as SarzakStore}; /// Convert a v1 Drawing format into a v2 Drawing format /// @@ -45,6 +47,7 @@ use crate::v2::sarzak::ObjectStore as SarzakStore; /// Well darn. There isn't a good way to get an object from an anchor, nor an /// anchor from an object -- not in the drawing domain anyway. /// +#[cfg(feature = "sarzak_mulit")] impl From<(&DrawingStore, &SarzakStore)> for ObjectStore { fn from((drawing, sarzak): (&DrawingStore, &SarzakStore)) -> Self { let mut merlin = ObjectStore::new(); @@ -192,6 +195,155 @@ impl From<(&DrawingStore, &SarzakStore)> for ObjectStore { } } +#[cfg(feature = "sarzak_single")] +impl From<(&DrawingStore, &SarzakStore)> for ObjectStore { + fn from((drawing, sarzak): (&DrawingStore, &SarzakStore)) -> Self { + let mut merlin = ObjectStore::new(); + + merlin.inter_edge(Arc::new(RwLock::new(Edge::Bottom(BOTTOM)))); + merlin.inter_edge(Arc::new(RwLock::new(Edge::Left(LEFT)))); + merlin.inter_edge(Arc::new(RwLock::new(Edge::Right(RIGHT)))); + merlin.inter_edge(Arc::new(RwLock::new(Edge::Top(TOP)))); + + for oui in drawing.iter_object_ui() { + let instance = Arc::new(RwLock::new(XBox::from((&*oui.read().unwrap(), drawing)))); + merlin.inter_x_box(instance); + } + + for bui in drawing.iter_binary_ui() { + let binary = &bui.read().unwrap(); + let binary = binary.r12_binary(sarzak)[0]; + let rel = &binary.r4_relationship(sarzak)[0]; + + let line = Line::new(&rel, &mut merlin); + let line_seg = LineSegment::new(&line, &mut merlin); + + // Default to putting the relationship at the midpoint of the line, + let bisection = Bisection::new(0.5, &line_seg, &mut merlin); + let _name = RelationshipName::new( + format!("R{}", binary.number), + 0, + 0, + &line, + &bisection, + &mut merlin, + ); + + let from_anchor = &bui.read().unwrap().r7_anchor(drawing)[0]; + + // Our relationships are jacked up, so we have to do the dumb thing. + // Not that relationship navigation is any better, depending on the + // direction. + let referrer = &binary.r6_referrer(sarzak)[0]; + let from_obj = &referrer.r17_object(sarzak)[0]; + let from_obj_ui = drawing + .iter_object_ui() + .find(|oui| oui.read().unwrap().object_id == from_obj.id) + .unwrap(); + + // Get what we need to build the offset to which the line connects. + let point = &from_anchor.read().unwrap().r4_point(drawing)[0]; + let edge = &from_anchor.read().unwrap().r3_edge(drawing)[0]; + let (x, y) = get_anchor_offset(&point, &edge); + + // Sort out how far along the edge the arrow should be drawn. + let origin = &from_obj_ui.read().unwrap().r13_point(drawing)[0]; + let offset = get_anchor_line_offset(&edge, &point, &from_obj_ui, &origin); + + // Sort out the glyph. + let card = &referrer.r9_cardinality(sarzak)[0]; + let glyph = match *card { + Cardinality::One(_) => Glyph::new_one(&line, &mut merlin), + Cardinality::Many(_) => Glyph::new_many(&line, &mut merlin), + }; + + // Get the box. + let x_box = merlin + .exhume_x_box(&from_obj_ui.read().unwrap().id) + .unwrap() + .clone(); + + // Create the anchor. + let from_anchor = Anchor::new( + offset, + x, + y, + &Arc::new(RwLock::new(XyzzyEdge(&edge, &merlin).into())), + &glyph, + &x_box, + &line, + &mut merlin, + ); + + // Create the from point + let point = Point::new_anchor( + point.read().unwrap().x, + point.read().unwrap().y, + &from_anchor, + &mut merlin, + ); + + // Create the "line segment point" + LineSegmentPoint::new(&line_seg, &point, &mut merlin); + + let to_anchor = &bui.read().unwrap().r8_anchor(drawing)[0]; + let referent = &binary.r5_referent(sarzak)[0]; + let from_obj = &referent.r16_object(sarzak)[0]; + let from_obj_ui = drawing + .iter_object_ui() + .find(|oui| oui.read().unwrap().object_id == from_obj.id) + .unwrap(); + + // Get what we need to build the offset to which the line connects. + let point = &to_anchor.read().unwrap().r4_point(drawing)[0]; + let edge = &to_anchor.read().unwrap().r3_edge(drawing)[0]; + let (x, y) = get_anchor_offset(&point, &edge); + + // Sort out how far along the edge the arrow should be drawn. + let origin = &from_obj_ui.read().unwrap().r13_point(drawing)[0]; + let offset = get_anchor_line_offset(&edge, &point, &from_obj_ui, &origin); + + // Sort out the glyph. + let card = &referent.r8_cardinality(sarzak)[0]; + let glyph = match *card { + Cardinality::One(_) => Glyph::new_one(&line, &mut merlin), + Cardinality::Many(_) => Glyph::new_many(&line, &mut merlin), + }; + + // Get the box. + let x_box = merlin + .exhume_x_box(&from_obj_ui.read().unwrap().id) + .unwrap() + .clone(); + + // Create the anchor. + let to_anchor = Anchor::new( + offset, + x, + y, + &Arc::new(RwLock::new(XyzzyEdge(&edge, &merlin).into())), + &glyph, + &x_box, + &line, + &mut merlin, + ); + + // Create the to point + let point = Point::new_anchor( + point.read().unwrap().x, + point.read().unwrap().y, + &to_anchor, + &mut merlin, + ); + + // Create the "line segment point" + LineSegmentPoint::new(&line_seg, &point, &mut merlin); + } + + merlin + } +} + fn get_anchor_offset(point: &Arc>, edge: &Arc>) -> (i64, i64) { let (x, y) = (point.read().unwrap().x, point.read().unwrap().y); diff --git a/src/v2/merlin/types/line.rs b/src/v2/merlin/types/line.rs index 8b4f056d..93ac5b38 100644 --- a/src/v2/merlin/types/line.rs +++ b/src/v2/merlin/types/line.rs @@ -10,11 +10,11 @@ use crate::v2::merlin::types::glyph::Glyph; use crate::v2::merlin::types::line_segment::LineSegment; use crate::v2::merlin::types::relationship_name::RelationshipName; use crate::v2::merlin::types::relationship_phrase::RelationshipPhrase; -use crate::v2::sarzak::types::relationship::Relationship; +use crate::v2::sarzak_single::types::relationship::Relationship; use serde::{Deserialize, Serialize}; use crate::v2::merlin::store::ObjectStore as MerlinStore; -use crate::v2::sarzak::store::ObjectStore as SarzakStore; +use crate::v2::sarzak_single::store::ObjectStore as SarzakStore; // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"line-struct-documentation"}}} @@ -50,10 +50,7 @@ impl Line { // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"line-struct-impl-nav-forward-to-relationship"}}} /// Navigate to [`Relationship`] across R2(1-*) - pub fn r2_relationship<'a>( - &'a self, - store: &'a SarzakStore, - ) -> Vec>> { + pub fn r2_relationship<'a>(&'a self, store: &'a SarzakStore) -> Vec<&Relationship> { span!("r2_relationship"); vec![store.exhume_relationship(&self.relationship).unwrap()] } diff --git a/src/v2/sarzak_single/from.rs b/src/v2/sarzak_single/from.rs index e201e15b..d7e1215c 100644 --- a/src/v2/sarzak_single/from.rs +++ b/src/v2/sarzak_single/from.rs @@ -8,23 +8,29 @@ //! It is hoped that the model has not changed enough to render //! these implementations useless. In any case it's expected that //! the generated code will need to be manually edited. -// {"magic":"","directive":{"Start":{"directive":"ignore-gen","tag":"v2::sarzak_single-from-impl-file"}}} -// {"magic":"","directive":{"Start":{"directive":"ignore-gen","tag":"v2::sarzak_single-from-impl-definition"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-gen","tag":"v2::sarzak-from-impl-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-gen","tag":"v2::sarzak-from-impl-definition"}}} +use uuid::Uuid; + use crate::v2::sarzak_single::types::{ AcknowledgedEvent, AnAssociativeReferent, Associative, AssociativeReferent, AssociativeReferrer, Attribute, Binary, Cardinality, Conditionality, Event, External, Isa, - Object, Referent, Referrer, Relationship, State, Subtype, Supertype, Ty, + Object, Referent, Referrer, Relationship, State, Subtype, Supertype, Ty, BOOLEAN, CONDITIONAL, + FLOAT, INTEGER, MANY, ONE, S_STRING, S_UUID, UNCONDITIONAL, }; use crate::v2::sarzak_single::ObjectStore; use crate::v1::sarzak::types::{ - AcknowledgedEvent as FromAcknowledgedEvent, AnAssociativeReferent as FromAnAssociativeReferent, - Associative as FromAssociative, AssociativeReferent as FromAssociativeReferent, - AssociativeReferrer as FromAssociativeReferrer, Attribute as FromAttribute, - Binary as FromBinary, Cardinality as FromCardinality, Conditionality as FromConditionality, - Event as FromEvent, External as FromExternal, Isa as FromIsa, Object as FromObject, - Referent as FromReferent, Referrer as FromReferrer, Relationship as FromRelationship, - State as FromState, Subtype as FromSubtype, Supertype as FromSupertype, Ty as FromTy, + AcknowledgedEvent as FromAcknowledgedEvent, Associative as FromAssociative, + AssociativeReferent as FromAssociativeReferent, AssociativeReferrer as FromAssociativeReferrer, + Attribute as FromAttribute, Binary as FromBinary, Cardinality as FromCardinality, + Conditionality as FromConditionality, Event as FromEvent, External as FromExternal, + Isa as FromIsa, Object as FromObject, Referent as FromReferent, Referrer as FromReferrer, + Relationship as FromRelationship, State as FromState, Subtype as FromSubtype, + Supertype as FromSupertype, Type as FromTy, BOOLEAN as FROM_BOOLEAN, + CONDITIONAL as FROM_CONDITIONAL, FLOAT as FROM_FLOAT, INTEGER as FROM_INTEGER, + MANY as FROM_MANY, ONE as FROM_ONE, STRING as FROM_STRING, UNCONDITIONAL as FROM_UNCONDITIONAL, + UUID as FROM_UUID, }; use crate::v1::sarzak::ObjectStore as SarzakStore; @@ -32,102 +38,100 @@ impl From<&SarzakStore> for ObjectStore { fn from(from: &SarzakStore) -> Self { let mut to = ObjectStore::new(); - for instance in from.iter_acknowledged_event() { + for (_, instance) in from.iter_acknowledged_event() { let instance = AcknowledgedEvent::from(instance); to.inter_acknowledged_event(instance); } - for instance in from.iter_an_associative_referent() { - let instance = AnAssociativeReferent::from(instance); - to.inter_an_associative_referent(instance); + // The order of the next two is important. We need the referents in the + // store before the associative in order to create the AnAssociativeReferent + // instances. + for (_, instance) in from.iter_associative_referent() { + let instance = AssociativeReferent::from(instance); + to.inter_associative_referent(instance); } - for instance in from.iter_associative() { - let instance = Associative::from(instance); + for (_, instance) in from.iter_associative() { + let instance = Associative::from((instance, from, &mut to)); to.inter_associative(instance); } - for instance in from.iter_associative_referent() { - let instance = AssociativeReferent::from(instance); - to.inter_associative_referent(instance); - } - - for instance in from.iter_associative_referrer() { + for (_, instance) in from.iter_associative_referrer() { let instance = AssociativeReferrer::from(instance); to.inter_associative_referrer(instance); } - for instance in from.iter_attribute() { + for (_, instance) in from.iter_attribute() { let instance = Attribute::from(instance); to.inter_attribute(instance); } - for instance in from.iter_binary() { + for (_, instance) in from.iter_binary() { let instance = Binary::from(instance); to.inter_binary(instance); } - for instance in from.iter_cardinality() { + for (_, instance) in from.iter_cardinality() { let instance = Cardinality::from(instance); to.inter_cardinality(instance); } - for instance in from.iter_conditionality() { + for (_, instance) in from.iter_conditionality() { let instance = Conditionality::from(instance); to.inter_conditionality(instance); } - for instance in from.iter_event() { + for (_, instance) in from.iter_event() { let instance = Event::from(instance); to.inter_event(instance); } - for instance in from.iter_external() { + for (_, instance) in from.iter_external() { let instance = External::from(instance); to.inter_external(instance); } - for instance in from.iter_isa() { + for (_, instance) in from.iter_isa() { let instance = Isa::from(instance); to.inter_isa(instance); } - for instance in from.iter_object() { + for (_, instance) in from.iter_object() { let instance = Object::from(instance); to.inter_object(instance); } - for instance in from.iter_referent() { + for (_, instance) in from.iter_referent() { let instance = Referent::from(instance); to.inter_referent(instance); } - for instance in from.iter_referrer() { + for (_, instance) in from.iter_referrer() { let instance = Referrer::from(instance); to.inter_referrer(instance); } - for instance in from.iter_relationship() { + for (_, instance) in from.iter_relationship() { let instance = Relationship::from(instance); to.inter_relationship(instance); } - for instance in from.iter_state() { + for (_, instance) in from.iter_state() { let instance = State::from(instance); to.inter_state(instance); } - for instance in from.iter_subtype() { + for (_, instance) in from.iter_subtype() { let instance = Subtype::from(instance); to.inter_subtype(instance); } - for instance in from.iter_supertype() { + for (_, instance) in from.iter_supertype() { let instance = Supertype::from(instance); to.inter_supertype(instance); } - for instance in from.iter_ty() { + for (_, instance) in from.iter_ty() { let instance = Ty::from(instance); to.inter_ty(instance); } @@ -146,35 +150,51 @@ impl From<&FromAcknowledgedEvent> for AcknowledgedEvent { } } -impl From<&FromAnAssociativeReferent> for AnAssociativeReferent { - fn from(src: &FromAnAssociativeReferent) -> Self { - Self { - id: src.id, - referential_attribute: src.referential_attribute.clone(), - associative: src.associative, - referent: src.referent, - } - } -} - -impl From<&FromAssociative> for Associative { - fn from(src: &FromAssociative) -> Self { - Self { +impl From<(&FromAssociative, &SarzakStore, &mut ObjectStore)> for Associative { + fn from((src, sarzak, store): (&FromAssociative, &SarzakStore, &mut ObjectStore)) -> Self { + let that = Self { id: src.id, number: src.number, from: src.from, - } + }; + let this = that.clone(); + + let referrer = sarzak.exhume_associative_referrer(&src.from).unwrap(); + + // Create instances of the associative object + let one = store.exhume_associative_referent(&src.one).unwrap().clone(); + let other = store + .exhume_associative_referent(&src.other) + .unwrap() + .clone(); + + let _ = AnAssociativeReferent::new( + referrer.one_referential_attribute.clone(), + &this, + &one, + store, + ); + let _ = AnAssociativeReferent::new( + referrer.other_referential_attribute.clone(), + &this, + &other, + store, + ); + + // This is seriously lame, but I don't think it's going to hurt anything. + let x = that; + x } } impl From<&FromAssociativeReferent> for AssociativeReferent { fn from(src: &FromAssociativeReferent) -> Self { Self { - description: src.description.clone(), id: src.id, - cardinality: src.cardinality, - conditionality: src.conditionality, obj_id: src.obj_id, + cardinality: from_const(&src.cardinality), + conditionality: from_const(&src.conditionality), + description: src.description.clone(), } } } @@ -183,8 +203,8 @@ impl From<&FromAssociativeReferrer> for AssociativeReferrer { fn from(src: &FromAssociativeReferrer) -> Self { Self { id: src.id, - cardinality: src.cardinality, obj_id: src.obj_id, + cardinality: from_const(&src.cardinality), } } } @@ -194,8 +214,8 @@ impl From<&FromAttribute> for Attribute { Self { id: src.id, name: src.name.clone(), - obj_id: src.obj_id, - ty: src.ty, + obj_id: src.obj_id.unwrap(), + ty: from_const(&src.ty), } } } @@ -205,8 +225,8 @@ impl From<&FromBinary> for Binary { Self { id: src.id, number: src.number, - from: src.from, to: src.to, + from: src.from, } } } @@ -214,8 +234,8 @@ impl From<&FromBinary> for Binary { impl From<&FromCardinality> for Cardinality { fn from(src: &FromCardinality) -> Self { match src { - FromCardinality::Many(src) => Cardinality::Many(MANY), - FromCardinality::One(src) => Cardinality::One(ONE), + FromCardinality::Many(_) => Cardinality::Many(MANY), + FromCardinality::One(_) => Cardinality::One(ONE), } } } @@ -223,8 +243,8 @@ impl From<&FromCardinality> for Cardinality { impl From<&FromConditionality> for Conditionality { fn from(src: &FromConditionality) -> Self { match src { - FromConditionality::Conditional(src) => Conditionality::Conditional(CONDITIONAL), - FromConditionality::Unconditional(src) => Conditionality::Unconditional(UNCONDITIONAL), + FromConditionality::Conditional(_) => Conditionality::Conditional(CONDITIONAL), + FromConditionality::Unconditional(_) => Conditionality::Unconditional(UNCONDITIONAL), } } } @@ -241,10 +261,10 @@ impl From<&FromEvent> for Event { impl From<&FromExternal> for External { fn from(src: &FromExternal) -> Self { Self { - ctor: src.ctor.clone(), id: src.id, + ctor: "new".to_owned(), name: src.name.clone(), - x_path: src.x_path.clone(), + x_path: src.path.clone(), } } } @@ -275,8 +295,8 @@ impl From<&FromReferent> for Referent { Self { description: src.description.clone(), id: src.id, - cardinality: src.cardinality, - conditionality: src.conditionality, + cardinality: from_const(&src.cardinality), + conditionality: from_const(&src.conditionality), obj_id: src.obj_id, } } @@ -288,8 +308,8 @@ impl From<&FromReferrer> for Referrer { description: src.description.clone(), id: src.id, referential_attribute: src.referential_attribute.clone(), - cardinality: src.cardinality, - conditionality: src.conditionality, + cardinality: from_const(&src.cardinality), + conditionality: from_const(&src.conditionality), obj_id: src.obj_id, } } @@ -298,9 +318,9 @@ impl From<&FromReferrer> for Referrer { impl From<&FromRelationship> for Relationship { fn from(src: &FromRelationship) -> Self { match src { - FromRelationship::Associative(src) => Relationship::Associative(ASSOCIATIVE), - FromRelationship::Binary(src) => Relationship::Binary(BINARY), - FromRelationship::Isa(src) => Relationship::Isa(ISA), + FromRelationship::Associative(src) => Relationship::Associative(*src), + FromRelationship::Binary(src) => Relationship::Binary(*src), + FromRelationship::Isa(src) => Relationship::Isa(*src), } } } @@ -336,15 +356,30 @@ impl From<&FromSupertype> for Supertype { impl From<&FromTy> for Ty { fn from(src: &FromTy) -> Self { match src { - FromTy::Boolean(src) => Ty::Boolean(BOOLEAN), - FromTy::External(src) => Ty::External(EXTERNAL), - FromTy::Float(src) => Ty::Float(FLOAT), - FromTy::Integer(src) => Ty::Integer(INTEGER), - FromTy::Object(src) => Ty::Object(OBJECT), - FromTy::SString(src) => Ty::SString(S_STRING), - FromTy::SUuid(src) => Ty::SUuid(S_UUID), + FromTy::Boolean(_) => Ty::Boolean(BOOLEAN), + FromTy::External(src) => Ty::External(*src), + FromTy::Float(_) => Ty::Float(FLOAT), + FromTy::Integer(_) => Ty::Integer(INTEGER), + FromTy::Object(src) => Ty::Object(*src), + FromTy::String(_) => Ty::SString(S_STRING), + FromTy::Uuid(_) => Ty::SUuid(S_UUID), } } } + +fn from_const(from: &Uuid) -> Uuid { + match *from { + FROM_BOOLEAN => BOOLEAN, + FROM_FLOAT => FLOAT, + FROM_INTEGER => INTEGER, + FROM_STRING => S_STRING, + FROM_UUID => S_UUID, + FROM_CONDITIONAL => CONDITIONAL, + FROM_UNCONDITIONAL => UNCONDITIONAL, + FROM_MANY => MANY, + FROM_ONE => ONE, + huh => panic!("from_const: unexpected value {}", huh), + } +} // {"magic":"","directive":{"End":{"directive":"ignore-gen"}}} // {"magic":"","directive":{"End":{"directive":"ignore-gen"}}} diff --git a/src/v2/sarzak_single/store.rs b/src/v2/sarzak_single/store.rs index 4020b640..c1254aaa 100644 --- a/src/v2/sarzak_single/store.rs +++ b/src/v2/sarzak_single/store.rs @@ -28,8 +28,6 @@ //! * [`Supertype`] //! * [`Ty`] // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::sarzak_single-object-store-definition"}}} -use std::cell::RefCell; -use std::rc::Rc; use std::{ fs, io::{self, prelude::*}, @@ -51,75 +49,68 @@ use crate::v2::sarzak_single::types::{ #[derive(Clone, Debug, Deserialize, Serialize)] pub struct ObjectStore { - acknowledged_event: Rc>, SystemTime)>>>, - an_associative_referent: - Rc>, SystemTime)>>>, - associative: Rc>, SystemTime)>>>, - associative_referent: - Rc>, SystemTime)>>>, - associative_referrer: - Rc>, SystemTime)>>>, - attribute: Rc>, SystemTime)>>>, - binary: Rc>, SystemTime)>>>, - cardinality: Rc>, SystemTime)>>>, - conditionality: Rc>, SystemTime)>>>, - event: Rc>, SystemTime)>>>, - external: Rc>, SystemTime)>>>, - isa: Rc>, SystemTime)>>>, - object: Rc>, SystemTime)>>>, - object_id_by_name: Rc>>, - referent: Rc>, SystemTime)>>>, - referrer: Rc>, SystemTime)>>>, - relationship: Rc>, SystemTime)>>>, - state: Rc>, SystemTime)>>>, - subtype: Rc>, SystemTime)>>>, - supertype: Rc>, SystemTime)>>>, - ty: Rc>, SystemTime)>>>, + acknowledged_event: HashMap, + an_associative_referent: HashMap, + associative: HashMap, + associative_referent: HashMap, + associative_referrer: HashMap, + attribute: HashMap, + binary: HashMap, + cardinality: HashMap, + conditionality: HashMap, + event: HashMap, + external: HashMap, + isa: HashMap, + object: HashMap, + object_id_by_name: HashMap, + referent: HashMap, + referrer: HashMap, + relationship: HashMap, + state: HashMap, + subtype: HashMap, + supertype: HashMap, + ty: HashMap, } impl ObjectStore { pub fn new() -> Self { let mut store = Self { - acknowledged_event: Rc::new(RefCell::new(HashMap::default())), - an_associative_referent: Rc::new(RefCell::new(HashMap::default())), - associative: Rc::new(RefCell::new(HashMap::default())), - associative_referent: Rc::new(RefCell::new(HashMap::default())), - associative_referrer: Rc::new(RefCell::new(HashMap::default())), - attribute: Rc::new(RefCell::new(HashMap::default())), - binary: Rc::new(RefCell::new(HashMap::default())), - cardinality: Rc::new(RefCell::new(HashMap::default())), - conditionality: Rc::new(RefCell::new(HashMap::default())), - event: Rc::new(RefCell::new(HashMap::default())), - external: Rc::new(RefCell::new(HashMap::default())), - isa: Rc::new(RefCell::new(HashMap::default())), - object: Rc::new(RefCell::new(HashMap::default())), - object_id_by_name: Rc::new(RefCell::new(HashMap::default())), - referent: Rc::new(RefCell::new(HashMap::default())), - referrer: Rc::new(RefCell::new(HashMap::default())), - relationship: Rc::new(RefCell::new(HashMap::default())), - state: Rc::new(RefCell::new(HashMap::default())), - subtype: Rc::new(RefCell::new(HashMap::default())), - supertype: Rc::new(RefCell::new(HashMap::default())), - ty: Rc::new(RefCell::new(HashMap::default())), + acknowledged_event: HashMap::default(), + an_associative_referent: HashMap::default(), + associative: HashMap::default(), + associative_referent: HashMap::default(), + associative_referrer: HashMap::default(), + attribute: HashMap::default(), + binary: HashMap::default(), + cardinality: HashMap::default(), + conditionality: HashMap::default(), + event: HashMap::default(), + external: HashMap::default(), + isa: HashMap::default(), + object: HashMap::default(), + object_id_by_name: HashMap::default(), + referent: HashMap::default(), + referrer: HashMap::default(), + relationship: HashMap::default(), + state: HashMap::default(), + subtype: HashMap::default(), + supertype: HashMap::default(), + ty: HashMap::default(), }; // Initialize Singleton Subtypes // 💥 Look at how beautiful this generated code is for super/sub-type graphs! // I remember having a bit of a struggle making it work. It's recursive, with // a lot of special cases, and I think it calls other recursive functions...💥 - store.inter_cardinality(Rc::new(RefCell::new(Cardinality::Many(MANY)))); - store.inter_cardinality(Rc::new(RefCell::new(Cardinality::One(ONE)))); - store.inter_conditionality(Rc::new(RefCell::new(Conditionality::Conditional( - CONDITIONAL, - )))); - store.inter_conditionality(Rc::new(RefCell::new(Conditionality::Unconditional( - UNCONDITIONAL, - )))); - store.inter_ty(Rc::new(RefCell::new(Ty::Boolean(BOOLEAN)))); - store.inter_ty(Rc::new(RefCell::new(Ty::Float(FLOAT)))); - store.inter_ty(Rc::new(RefCell::new(Ty::Integer(INTEGER)))); - store.inter_ty(Rc::new(RefCell::new(Ty::SString(S_STRING)))); - store.inter_ty(Rc::new(RefCell::new(Ty::SUuid(S_UUID)))); + store.inter_cardinality(Cardinality::Many(MANY)); + store.inter_cardinality(Cardinality::One(ONE)); + store.inter_conditionality(Conditionality::Conditional(CONDITIONAL)); + store.inter_conditionality(Conditionality::Unconditional(UNCONDITIONAL)); + store.inter_ty(Ty::Boolean(BOOLEAN)); + store.inter_ty(Ty::Float(FLOAT)); + store.inter_ty(Ty::Integer(INTEGER)); + store.inter_ty(Ty::SString(S_STRING)); + store.inter_ty(Ty::SUuid(S_UUID)); store } @@ -127,47 +118,35 @@ impl ObjectStore { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::sarzak_single-object-store-methods"}}} /// Inter (insert) [`AcknowledgedEvent`] into the store. /// - pub fn inter_acknowledged_event(&mut self, acknowledged_event: Rc>) { - let read = acknowledged_event.borrow(); - self.acknowledged_event - .borrow_mut() - .insert(read.id, (acknowledged_event.clone(), SystemTime::now())); + pub fn inter_acknowledged_event(&mut self, acknowledged_event: AcknowledgedEvent) { + self.acknowledged_event.insert( + acknowledged_event.id, + (acknowledged_event, SystemTime::now()), + ); } /// Exhume (get) [`AcknowledgedEvent`] from the store. /// - pub fn exhume_acknowledged_event(&self, id: &Uuid) -> Option>> { + pub fn exhume_acknowledged_event(&self, id: &Uuid) -> Option<&AcknowledgedEvent> { self.acknowledged_event - .borrow() .get(id) - .map(|acknowledged_event| acknowledged_event.0.clone()) + .map(|acknowledged_event| &acknowledged_event.0) } /// Exorcise (remove) [`AcknowledgedEvent`] from the store. /// - pub fn exorcise_acknowledged_event( - &mut self, - id: &Uuid, - ) -> Option>> { + pub fn exorcise_acknowledged_event(&mut self, id: &Uuid) -> Option { self.acknowledged_event - .borrow_mut() .remove(id) - .map(|acknowledged_event| acknowledged_event.0.clone()) + .map(|acknowledged_event| acknowledged_event.0) } /// Get an iterator over the internal `HashMap<&Uuid, AcknowledgedEvent>`. /// - pub fn iter_acknowledged_event( - &self, - ) -> impl Iterator>> + '_ { - let values: Vec>> = self - .acknowledged_event - .borrow() + pub fn iter_acknowledged_event(&self) -> impl Iterator { + self.acknowledged_event .values() - .map(|acknowledged_event| acknowledged_event.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + .map(|acknowledged_event| &acknowledged_event.0) } /// Get the timestamp for AcknowledgedEvent. @@ -177,7 +156,6 @@ impl ObjectStore { acknowledged_event: &AcknowledgedEvent, ) -> SystemTime { self.acknowledged_event - .borrow() .get(&acknowledged_event.id) .map(|acknowledged_event| acknowledged_event.1) .unwrap_or(SystemTime::now()) @@ -187,52 +165,36 @@ impl ObjectStore { /// pub fn inter_an_associative_referent( &mut self, - an_associative_referent: Rc>, + an_associative_referent: AnAssociativeReferent, ) { - let read = an_associative_referent.borrow(); - self.an_associative_referent.borrow_mut().insert( - read.id, - (an_associative_referent.clone(), SystemTime::now()), + self.an_associative_referent.insert( + an_associative_referent.id, + (an_associative_referent, SystemTime::now()), ); } /// Exhume (get) [`AnAssociativeReferent`] from the store. /// - pub fn exhume_an_associative_referent( - &self, - id: &Uuid, - ) -> Option>> { + pub fn exhume_an_associative_referent(&self, id: &Uuid) -> Option<&AnAssociativeReferent> { self.an_associative_referent - .borrow() .get(id) - .map(|an_associative_referent| an_associative_referent.0.clone()) + .map(|an_associative_referent| &an_associative_referent.0) } /// Exorcise (remove) [`AnAssociativeReferent`] from the store. /// - pub fn exorcise_an_associative_referent( - &mut self, - id: &Uuid, - ) -> Option>> { + pub fn exorcise_an_associative_referent(&mut self, id: &Uuid) -> Option { self.an_associative_referent - .borrow_mut() .remove(id) - .map(|an_associative_referent| an_associative_referent.0.clone()) + .map(|an_associative_referent| an_associative_referent.0) } /// Get an iterator over the internal `HashMap<&Uuid, AnAssociativeReferent>`. /// - pub fn iter_an_associative_referent( - &self, - ) -> impl Iterator>> + '_ { - let values: Vec>> = self - .an_associative_referent - .borrow() + pub fn iter_an_associative_referent(&self) -> impl Iterator { + self.an_associative_referent .values() - .map(|an_associative_referent| an_associative_referent.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + .map(|an_associative_referent| &an_associative_referent.0) } /// Get the timestamp for AnAssociativeReferent. @@ -242,7 +204,6 @@ impl ObjectStore { an_associative_referent: &AnAssociativeReferent, ) -> SystemTime { self.an_associative_referent - .borrow() .get(&an_associative_referent.id) .map(|an_associative_referent| an_associative_referent.1) .unwrap_or(SystemTime::now()) @@ -250,49 +211,33 @@ impl ObjectStore { /// Inter (insert) [`Associative`] into the store. /// - pub fn inter_associative(&mut self, associative: Rc>) { - let read = associative.borrow(); + pub fn inter_associative(&mut self, associative: Associative) { self.associative - .borrow_mut() - .insert(read.id, (associative.clone(), SystemTime::now())); + .insert(associative.id, (associative, SystemTime::now())); } /// Exhume (get) [`Associative`] from the store. /// - pub fn exhume_associative(&self, id: &Uuid) -> Option>> { - self.associative - .borrow() - .get(id) - .map(|associative| associative.0.clone()) + pub fn exhume_associative(&self, id: &Uuid) -> Option<&Associative> { + self.associative.get(id).map(|associative| &associative.0) } /// Exorcise (remove) [`Associative`] from the store. /// - pub fn exorcise_associative(&mut self, id: &Uuid) -> Option>> { - self.associative - .borrow_mut() - .remove(id) - .map(|associative| associative.0.clone()) + pub fn exorcise_associative(&mut self, id: &Uuid) -> Option { + self.associative.remove(id).map(|associative| associative.0) } /// Get an iterator over the internal `HashMap<&Uuid, Associative>`. /// - pub fn iter_associative(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .associative - .borrow() - .values() - .map(|associative| associative.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_associative(&self) -> impl Iterator { + self.associative.values().map(|associative| &associative.0) } /// Get the timestamp for Associative. /// pub fn associative_timestamp(&self, associative: &Associative) -> SystemTime { self.associative - .borrow() .get(&associative.id) .map(|associative| associative.1) .unwrap_or(SystemTime::now()) @@ -300,53 +245,35 @@ impl ObjectStore { /// Inter (insert) [`AssociativeReferent`] into the store. /// - pub fn inter_associative_referent( - &mut self, - associative_referent: Rc>, - ) { - let read = associative_referent.borrow(); - self.associative_referent - .borrow_mut() - .insert(read.id, (associative_referent.clone(), SystemTime::now())); + pub fn inter_associative_referent(&mut self, associative_referent: AssociativeReferent) { + self.associative_referent.insert( + associative_referent.id, + (associative_referent, SystemTime::now()), + ); } /// Exhume (get) [`AssociativeReferent`] from the store. /// - pub fn exhume_associative_referent( - &self, - id: &Uuid, - ) -> Option>> { + pub fn exhume_associative_referent(&self, id: &Uuid) -> Option<&AssociativeReferent> { self.associative_referent - .borrow() .get(id) - .map(|associative_referent| associative_referent.0.clone()) + .map(|associative_referent| &associative_referent.0) } /// Exorcise (remove) [`AssociativeReferent`] from the store. /// - pub fn exorcise_associative_referent( - &mut self, - id: &Uuid, - ) -> Option>> { + pub fn exorcise_associative_referent(&mut self, id: &Uuid) -> Option { self.associative_referent - .borrow_mut() .remove(id) - .map(|associative_referent| associative_referent.0.clone()) + .map(|associative_referent| associative_referent.0) } /// Get an iterator over the internal `HashMap<&Uuid, AssociativeReferent>`. /// - pub fn iter_associative_referent( - &self, - ) -> impl Iterator>> + '_ { - let values: Vec>> = self - .associative_referent - .borrow() + pub fn iter_associative_referent(&self) -> impl Iterator { + self.associative_referent .values() - .map(|associative_referent| associative_referent.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + .map(|associative_referent| &associative_referent.0) } /// Get the timestamp for AssociativeReferent. @@ -356,7 +283,6 @@ impl ObjectStore { associative_referent: &AssociativeReferent, ) -> SystemTime { self.associative_referent - .borrow() .get(&associative_referent.id) .map(|associative_referent| associative_referent.1) .unwrap_or(SystemTime::now()) @@ -364,53 +290,35 @@ impl ObjectStore { /// Inter (insert) [`AssociativeReferrer`] into the store. /// - pub fn inter_associative_referrer( - &mut self, - associative_referrer: Rc>, - ) { - let read = associative_referrer.borrow(); - self.associative_referrer - .borrow_mut() - .insert(read.id, (associative_referrer.clone(), SystemTime::now())); + pub fn inter_associative_referrer(&mut self, associative_referrer: AssociativeReferrer) { + self.associative_referrer.insert( + associative_referrer.id, + (associative_referrer, SystemTime::now()), + ); } /// Exhume (get) [`AssociativeReferrer`] from the store. /// - pub fn exhume_associative_referrer( - &self, - id: &Uuid, - ) -> Option>> { + pub fn exhume_associative_referrer(&self, id: &Uuid) -> Option<&AssociativeReferrer> { self.associative_referrer - .borrow() .get(id) - .map(|associative_referrer| associative_referrer.0.clone()) + .map(|associative_referrer| &associative_referrer.0) } /// Exorcise (remove) [`AssociativeReferrer`] from the store. /// - pub fn exorcise_associative_referrer( - &mut self, - id: &Uuid, - ) -> Option>> { + pub fn exorcise_associative_referrer(&mut self, id: &Uuid) -> Option { self.associative_referrer - .borrow_mut() .remove(id) - .map(|associative_referrer| associative_referrer.0.clone()) + .map(|associative_referrer| associative_referrer.0) } /// Get an iterator over the internal `HashMap<&Uuid, AssociativeReferrer>`. /// - pub fn iter_associative_referrer( - &self, - ) -> impl Iterator>> + '_ { - let values: Vec>> = self - .associative_referrer - .borrow() + pub fn iter_associative_referrer(&self) -> impl Iterator { + self.associative_referrer .values() - .map(|associative_referrer| associative_referrer.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + .map(|associative_referrer| &associative_referrer.0) } /// Get the timestamp for AssociativeReferrer. @@ -420,7 +328,6 @@ impl ObjectStore { associative_referrer: &AssociativeReferrer, ) -> SystemTime { self.associative_referrer - .borrow() .get(&associative_referrer.id) .map(|associative_referrer| associative_referrer.1) .unwrap_or(SystemTime::now()) @@ -428,49 +335,33 @@ impl ObjectStore { /// Inter (insert) [`Attribute`] into the store. /// - pub fn inter_attribute(&mut self, attribute: Rc>) { - let read = attribute.borrow(); + pub fn inter_attribute(&mut self, attribute: Attribute) { self.attribute - .borrow_mut() - .insert(read.id, (attribute.clone(), SystemTime::now())); + .insert(attribute.id, (attribute, SystemTime::now())); } /// Exhume (get) [`Attribute`] from the store. /// - pub fn exhume_attribute(&self, id: &Uuid) -> Option>> { - self.attribute - .borrow() - .get(id) - .map(|attribute| attribute.0.clone()) + pub fn exhume_attribute(&self, id: &Uuid) -> Option<&Attribute> { + self.attribute.get(id).map(|attribute| &attribute.0) } /// Exorcise (remove) [`Attribute`] from the store. /// - pub fn exorcise_attribute(&mut self, id: &Uuid) -> Option>> { - self.attribute - .borrow_mut() - .remove(id) - .map(|attribute| attribute.0.clone()) + pub fn exorcise_attribute(&mut self, id: &Uuid) -> Option { + self.attribute.remove(id).map(|attribute| attribute.0) } /// Get an iterator over the internal `HashMap<&Uuid, Attribute>`. /// - pub fn iter_attribute(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .attribute - .borrow() - .values() - .map(|attribute| attribute.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_attribute(&self) -> impl Iterator { + self.attribute.values().map(|attribute| &attribute.0) } /// Get the timestamp for Attribute. /// pub fn attribute_timestamp(&self, attribute: &Attribute) -> SystemTime { self.attribute - .borrow() .get(&attribute.id) .map(|attribute| attribute.1) .unwrap_or(SystemTime::now()) @@ -478,46 +369,32 @@ impl ObjectStore { /// Inter (insert) [`Binary`] into the store. /// - pub fn inter_binary(&mut self, binary: Rc>) { - let read = binary.borrow(); - self.binary - .borrow_mut() - .insert(read.id, (binary.clone(), SystemTime::now())); + pub fn inter_binary(&mut self, binary: Binary) { + self.binary.insert(binary.id, (binary, SystemTime::now())); } /// Exhume (get) [`Binary`] from the store. /// - pub fn exhume_binary(&self, id: &Uuid) -> Option>> { - self.binary.borrow().get(id).map(|binary| binary.0.clone()) + pub fn exhume_binary(&self, id: &Uuid) -> Option<&Binary> { + self.binary.get(id).map(|binary| &binary.0) } /// Exorcise (remove) [`Binary`] from the store. /// - pub fn exorcise_binary(&mut self, id: &Uuid) -> Option>> { - self.binary - .borrow_mut() - .remove(id) - .map(|binary| binary.0.clone()) + pub fn exorcise_binary(&mut self, id: &Uuid) -> Option { + self.binary.remove(id).map(|binary| binary.0) } /// Get an iterator over the internal `HashMap<&Uuid, Binary>`. /// - pub fn iter_binary(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .binary - .borrow() - .values() - .map(|binary| binary.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_binary(&self) -> impl Iterator { + self.binary.values().map(|binary| &binary.0) } /// Get the timestamp for Binary. /// pub fn binary_timestamp(&self, binary: &Binary) -> SystemTime { self.binary - .borrow() .get(&binary.id) .map(|binary| binary.1) .unwrap_or(SystemTime::now()) @@ -525,49 +402,33 @@ impl ObjectStore { /// Inter (insert) [`Cardinality`] into the store. /// - pub fn inter_cardinality(&mut self, cardinality: Rc>) { - let read = cardinality.borrow(); + pub fn inter_cardinality(&mut self, cardinality: Cardinality) { self.cardinality - .borrow_mut() - .insert(read.id(), (cardinality.clone(), SystemTime::now())); + .insert(cardinality.id(), (cardinality, SystemTime::now())); } /// Exhume (get) [`Cardinality`] from the store. /// - pub fn exhume_cardinality(&self, id: &Uuid) -> Option>> { - self.cardinality - .borrow() - .get(id) - .map(|cardinality| cardinality.0.clone()) + pub fn exhume_cardinality(&self, id: &Uuid) -> Option<&Cardinality> { + self.cardinality.get(id).map(|cardinality| &cardinality.0) } /// Exorcise (remove) [`Cardinality`] from the store. /// - pub fn exorcise_cardinality(&mut self, id: &Uuid) -> Option>> { - self.cardinality - .borrow_mut() - .remove(id) - .map(|cardinality| cardinality.0.clone()) + pub fn exorcise_cardinality(&mut self, id: &Uuid) -> Option { + self.cardinality.remove(id).map(|cardinality| cardinality.0) } /// Get an iterator over the internal `HashMap<&Uuid, Cardinality>`. /// - pub fn iter_cardinality(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .cardinality - .borrow() - .values() - .map(|cardinality| cardinality.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_cardinality(&self) -> impl Iterator { + self.cardinality.values().map(|cardinality| &cardinality.0) } /// Get the timestamp for Cardinality. /// pub fn cardinality_timestamp(&self, cardinality: &Cardinality) -> SystemTime { self.cardinality - .borrow() .get(&cardinality.id()) .map(|cardinality| cardinality.1) .unwrap_or(SystemTime::now()) @@ -575,49 +436,39 @@ impl ObjectStore { /// Inter (insert) [`Conditionality`] into the store. /// - pub fn inter_conditionality(&mut self, conditionality: Rc>) { - let read = conditionality.borrow(); + pub fn inter_conditionality(&mut self, conditionality: Conditionality) { self.conditionality - .borrow_mut() - .insert(read.id(), (conditionality.clone(), SystemTime::now())); + .insert(conditionality.id(), (conditionality, SystemTime::now())); } /// Exhume (get) [`Conditionality`] from the store. /// - pub fn exhume_conditionality(&self, id: &Uuid) -> Option>> { + pub fn exhume_conditionality(&self, id: &Uuid) -> Option<&Conditionality> { self.conditionality - .borrow() .get(id) - .map(|conditionality| conditionality.0.clone()) + .map(|conditionality| &conditionality.0) } /// Exorcise (remove) [`Conditionality`] from the store. /// - pub fn exorcise_conditionality(&mut self, id: &Uuid) -> Option>> { + pub fn exorcise_conditionality(&mut self, id: &Uuid) -> Option { self.conditionality - .borrow_mut() .remove(id) - .map(|conditionality| conditionality.0.clone()) + .map(|conditionality| conditionality.0) } /// Get an iterator over the internal `HashMap<&Uuid, Conditionality>`. /// - pub fn iter_conditionality(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .conditionality - .borrow() + pub fn iter_conditionality(&self) -> impl Iterator { + self.conditionality .values() - .map(|conditionality| conditionality.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + .map(|conditionality| &conditionality.0) } /// Get the timestamp for Conditionality. /// pub fn conditionality_timestamp(&self, conditionality: &Conditionality) -> SystemTime { self.conditionality - .borrow() .get(&conditionality.id()) .map(|conditionality| conditionality.1) .unwrap_or(SystemTime::now()) @@ -625,46 +476,32 @@ impl ObjectStore { /// Inter (insert) [`Event`] into the store. /// - pub fn inter_event(&mut self, event: Rc>) { - let read = event.borrow(); - self.event - .borrow_mut() - .insert(read.id, (event.clone(), SystemTime::now())); + pub fn inter_event(&mut self, event: Event) { + self.event.insert(event.id, (event, SystemTime::now())); } /// Exhume (get) [`Event`] from the store. /// - pub fn exhume_event(&self, id: &Uuid) -> Option>> { - self.event.borrow().get(id).map(|event| event.0.clone()) + pub fn exhume_event(&self, id: &Uuid) -> Option<&Event> { + self.event.get(id).map(|event| &event.0) } /// Exorcise (remove) [`Event`] from the store. /// - pub fn exorcise_event(&mut self, id: &Uuid) -> Option>> { - self.event - .borrow_mut() - .remove(id) - .map(|event| event.0.clone()) + pub fn exorcise_event(&mut self, id: &Uuid) -> Option { + self.event.remove(id).map(|event| event.0) } /// Get an iterator over the internal `HashMap<&Uuid, Event>`. /// - pub fn iter_event(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .event - .borrow() - .values() - .map(|event| event.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_event(&self) -> impl Iterator { + self.event.values().map(|event| &event.0) } /// Get the timestamp for Event. /// pub fn event_timestamp(&self, event: &Event) -> SystemTime { self.event - .borrow() .get(&event.id) .map(|event| event.1) .unwrap_or(SystemTime::now()) @@ -672,49 +509,33 @@ impl ObjectStore { /// Inter (insert) [`External`] into the store. /// - pub fn inter_external(&mut self, external: Rc>) { - let read = external.borrow(); + pub fn inter_external(&mut self, external: External) { self.external - .borrow_mut() - .insert(read.id, (external.clone(), SystemTime::now())); + .insert(external.id, (external, SystemTime::now())); } /// Exhume (get) [`External`] from the store. /// - pub fn exhume_external(&self, id: &Uuid) -> Option>> { - self.external - .borrow() - .get(id) - .map(|external| external.0.clone()) + pub fn exhume_external(&self, id: &Uuid) -> Option<&External> { + self.external.get(id).map(|external| &external.0) } /// Exorcise (remove) [`External`] from the store. /// - pub fn exorcise_external(&mut self, id: &Uuid) -> Option>> { - self.external - .borrow_mut() - .remove(id) - .map(|external| external.0.clone()) + pub fn exorcise_external(&mut self, id: &Uuid) -> Option { + self.external.remove(id).map(|external| external.0) } /// Get an iterator over the internal `HashMap<&Uuid, External>`. /// - pub fn iter_external(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .external - .borrow() - .values() - .map(|external| external.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_external(&self) -> impl Iterator { + self.external.values().map(|external| &external.0) } /// Get the timestamp for External. /// pub fn external_timestamp(&self, external: &External) -> SystemTime { self.external - .borrow() .get(&external.id) .map(|external| external.1) .unwrap_or(SystemTime::now()) @@ -722,43 +543,32 @@ impl ObjectStore { /// Inter (insert) [`Isa`] into the store. /// - pub fn inter_isa(&mut self, isa: Rc>) { - let read = isa.borrow(); - self.isa - .borrow_mut() - .insert(read.id, (isa.clone(), SystemTime::now())); + pub fn inter_isa(&mut self, isa: Isa) { + self.isa.insert(isa.id, (isa, SystemTime::now())); } /// Exhume (get) [`Isa`] from the store. /// - pub fn exhume_isa(&self, id: &Uuid) -> Option>> { - self.isa.borrow().get(id).map(|isa| isa.0.clone()) + pub fn exhume_isa(&self, id: &Uuid) -> Option<&Isa> { + self.isa.get(id).map(|isa| &isa.0) } /// Exorcise (remove) [`Isa`] from the store. /// - pub fn exorcise_isa(&mut self, id: &Uuid) -> Option>> { - self.isa.borrow_mut().remove(id).map(|isa| isa.0.clone()) + pub fn exorcise_isa(&mut self, id: &Uuid) -> Option { + self.isa.remove(id).map(|isa| isa.0) } /// Get an iterator over the internal `HashMap<&Uuid, Isa>`. /// - pub fn iter_isa(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .isa - .borrow() - .values() - .map(|isa| isa.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_isa(&self) -> impl Iterator { + self.isa.values().map(|isa| &isa.0) } /// Get the timestamp for Isa. /// pub fn isa_timestamp(&self, isa: &Isa) -> SystemTime { self.isa - .borrow() .get(&isa.id) .map(|isa| isa.1) .unwrap_or(SystemTime::now()) @@ -766,57 +576,41 @@ impl ObjectStore { /// Inter (insert) [`Object`] into the store. /// - pub fn inter_object(&mut self, object: Rc>) { - let read = object.borrow(); - let value = (object.clone(), SystemTime::now()); + pub fn inter_object(&mut self, object: Object) { + let value = (object, SystemTime::now()); self.object_id_by_name - .borrow_mut() - .insert(read.name.to_upper_camel_case(), (read.id, value.1)); - self.object.borrow_mut().insert(read.id, value); + .insert(value.0.name.to_upper_camel_case(), (value.0.id, value.1)); + self.object.insert(value.0.id, value); } /// Exhume (get) [`Object`] from the store. /// - pub fn exhume_object(&self, id: &Uuid) -> Option>> { - self.object.borrow().get(id).map(|object| object.0.clone()) + pub fn exhume_object(&self, id: &Uuid) -> Option<&Object> { + self.object.get(id).map(|object| &object.0) } /// Exorcise (remove) [`Object`] from the store. /// - pub fn exorcise_object(&mut self, id: &Uuid) -> Option>> { - self.object - .borrow_mut() - .remove(id) - .map(|object| object.0.clone()) + pub fn exorcise_object(&mut self, id: &Uuid) -> Option { + self.object.remove(id).map(|object| object.0) } /// Exhume [`Object`] id from the store by name. /// pub fn exhume_object_id_by_name(&self, name: &str) -> Option { - self.object_id_by_name - .borrow() - .get(name) - .map(|object| object.0) + self.object_id_by_name.get(name).map(|object| object.0) } /// Get an iterator over the internal `HashMap<&Uuid, Object>`. /// - pub fn iter_object(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .object - .borrow() - .values() - .map(|object| object.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_object(&self) -> impl Iterator { + self.object.values().map(|object| &object.0) } /// Get the timestamp for Object. /// pub fn object_timestamp(&self, object: &Object) -> SystemTime { self.object - .borrow() .get(&object.id) .map(|object| object.1) .unwrap_or(SystemTime::now()) @@ -824,49 +618,33 @@ impl ObjectStore { /// Inter (insert) [`Referent`] into the store. /// - pub fn inter_referent(&mut self, referent: Rc>) { - let read = referent.borrow(); + pub fn inter_referent(&mut self, referent: Referent) { self.referent - .borrow_mut() - .insert(read.id, (referent.clone(), SystemTime::now())); + .insert(referent.id, (referent, SystemTime::now())); } /// Exhume (get) [`Referent`] from the store. /// - pub fn exhume_referent(&self, id: &Uuid) -> Option>> { - self.referent - .borrow() - .get(id) - .map(|referent| referent.0.clone()) + pub fn exhume_referent(&self, id: &Uuid) -> Option<&Referent> { + self.referent.get(id).map(|referent| &referent.0) } /// Exorcise (remove) [`Referent`] from the store. /// - pub fn exorcise_referent(&mut self, id: &Uuid) -> Option>> { - self.referent - .borrow_mut() - .remove(id) - .map(|referent| referent.0.clone()) + pub fn exorcise_referent(&mut self, id: &Uuid) -> Option { + self.referent.remove(id).map(|referent| referent.0) } /// Get an iterator over the internal `HashMap<&Uuid, Referent>`. /// - pub fn iter_referent(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .referent - .borrow() - .values() - .map(|referent| referent.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_referent(&self) -> impl Iterator { + self.referent.values().map(|referent| &referent.0) } /// Get the timestamp for Referent. /// pub fn referent_timestamp(&self, referent: &Referent) -> SystemTime { self.referent - .borrow() .get(&referent.id) .map(|referent| referent.1) .unwrap_or(SystemTime::now()) @@ -874,49 +652,33 @@ impl ObjectStore { /// Inter (insert) [`Referrer`] into the store. /// - pub fn inter_referrer(&mut self, referrer: Rc>) { - let read = referrer.borrow(); + pub fn inter_referrer(&mut self, referrer: Referrer) { self.referrer - .borrow_mut() - .insert(read.id, (referrer.clone(), SystemTime::now())); + .insert(referrer.id, (referrer, SystemTime::now())); } /// Exhume (get) [`Referrer`] from the store. /// - pub fn exhume_referrer(&self, id: &Uuid) -> Option>> { - self.referrer - .borrow() - .get(id) - .map(|referrer| referrer.0.clone()) + pub fn exhume_referrer(&self, id: &Uuid) -> Option<&Referrer> { + self.referrer.get(id).map(|referrer| &referrer.0) } /// Exorcise (remove) [`Referrer`] from the store. /// - pub fn exorcise_referrer(&mut self, id: &Uuid) -> Option>> { - self.referrer - .borrow_mut() - .remove(id) - .map(|referrer| referrer.0.clone()) + pub fn exorcise_referrer(&mut self, id: &Uuid) -> Option { + self.referrer.remove(id).map(|referrer| referrer.0) } /// Get an iterator over the internal `HashMap<&Uuid, Referrer>`. /// - pub fn iter_referrer(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .referrer - .borrow() - .values() - .map(|referrer| referrer.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_referrer(&self) -> impl Iterator { + self.referrer.values().map(|referrer| &referrer.0) } /// Get the timestamp for Referrer. /// pub fn referrer_timestamp(&self, referrer: &Referrer) -> SystemTime { self.referrer - .borrow() .get(&referrer.id) .map(|referrer| referrer.1) .unwrap_or(SystemTime::now()) @@ -924,49 +686,39 @@ impl ObjectStore { /// Inter (insert) [`Relationship`] into the store. /// - pub fn inter_relationship(&mut self, relationship: Rc>) { - let read = relationship.borrow(); + pub fn inter_relationship(&mut self, relationship: Relationship) { self.relationship - .borrow_mut() - .insert(read.id(), (relationship.clone(), SystemTime::now())); + .insert(relationship.id(), (relationship, SystemTime::now())); } /// Exhume (get) [`Relationship`] from the store. /// - pub fn exhume_relationship(&self, id: &Uuid) -> Option>> { + pub fn exhume_relationship(&self, id: &Uuid) -> Option<&Relationship> { self.relationship - .borrow() .get(id) - .map(|relationship| relationship.0.clone()) + .map(|relationship| &relationship.0) } /// Exorcise (remove) [`Relationship`] from the store. /// - pub fn exorcise_relationship(&mut self, id: &Uuid) -> Option>> { + pub fn exorcise_relationship(&mut self, id: &Uuid) -> Option { self.relationship - .borrow_mut() .remove(id) - .map(|relationship| relationship.0.clone()) + .map(|relationship| relationship.0) } /// Get an iterator over the internal `HashMap<&Uuid, Relationship>`. /// - pub fn iter_relationship(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .relationship - .borrow() + pub fn iter_relationship(&self) -> impl Iterator { + self.relationship .values() - .map(|relationship| relationship.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + .map(|relationship| &relationship.0) } /// Get the timestamp for Relationship. /// pub fn relationship_timestamp(&self, relationship: &Relationship) -> SystemTime { self.relationship - .borrow() .get(&relationship.id()) .map(|relationship| relationship.1) .unwrap_or(SystemTime::now()) @@ -974,46 +726,32 @@ impl ObjectStore { /// Inter (insert) [`State`] into the store. /// - pub fn inter_state(&mut self, state: Rc>) { - let read = state.borrow(); - self.state - .borrow_mut() - .insert(read.id, (state.clone(), SystemTime::now())); + pub fn inter_state(&mut self, state: State) { + self.state.insert(state.id, (state, SystemTime::now())); } /// Exhume (get) [`State`] from the store. /// - pub fn exhume_state(&self, id: &Uuid) -> Option>> { - self.state.borrow().get(id).map(|state| state.0.clone()) + pub fn exhume_state(&self, id: &Uuid) -> Option<&State> { + self.state.get(id).map(|state| &state.0) } /// Exorcise (remove) [`State`] from the store. /// - pub fn exorcise_state(&mut self, id: &Uuid) -> Option>> { - self.state - .borrow_mut() - .remove(id) - .map(|state| state.0.clone()) + pub fn exorcise_state(&mut self, id: &Uuid) -> Option { + self.state.remove(id).map(|state| state.0) } /// Get an iterator over the internal `HashMap<&Uuid, State>`. /// - pub fn iter_state(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .state - .borrow() - .values() - .map(|state| state.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_state(&self) -> impl Iterator { + self.state.values().map(|state| &state.0) } /// Get the timestamp for State. /// pub fn state_timestamp(&self, state: &State) -> SystemTime { self.state - .borrow() .get(&state.id) .map(|state| state.1) .unwrap_or(SystemTime::now()) @@ -1021,49 +759,33 @@ impl ObjectStore { /// Inter (insert) [`Subtype`] into the store. /// - pub fn inter_subtype(&mut self, subtype: Rc>) { - let read = subtype.borrow(); + pub fn inter_subtype(&mut self, subtype: Subtype) { self.subtype - .borrow_mut() - .insert(read.id, (subtype.clone(), SystemTime::now())); + .insert(subtype.id, (subtype, SystemTime::now())); } /// Exhume (get) [`Subtype`] from the store. /// - pub fn exhume_subtype(&self, id: &Uuid) -> Option>> { - self.subtype - .borrow() - .get(id) - .map(|subtype| subtype.0.clone()) + pub fn exhume_subtype(&self, id: &Uuid) -> Option<&Subtype> { + self.subtype.get(id).map(|subtype| &subtype.0) } /// Exorcise (remove) [`Subtype`] from the store. /// - pub fn exorcise_subtype(&mut self, id: &Uuid) -> Option>> { - self.subtype - .borrow_mut() - .remove(id) - .map(|subtype| subtype.0.clone()) + pub fn exorcise_subtype(&mut self, id: &Uuid) -> Option { + self.subtype.remove(id).map(|subtype| subtype.0) } /// Get an iterator over the internal `HashMap<&Uuid, Subtype>`. /// - pub fn iter_subtype(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .subtype - .borrow() - .values() - .map(|subtype| subtype.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_subtype(&self) -> impl Iterator { + self.subtype.values().map(|subtype| &subtype.0) } /// Get the timestamp for Subtype. /// pub fn subtype_timestamp(&self, subtype: &Subtype) -> SystemTime { self.subtype - .borrow() .get(&subtype.id) .map(|subtype| subtype.1) .unwrap_or(SystemTime::now()) @@ -1071,49 +793,33 @@ impl ObjectStore { /// Inter (insert) [`Supertype`] into the store. /// - pub fn inter_supertype(&mut self, supertype: Rc>) { - let read = supertype.borrow(); + pub fn inter_supertype(&mut self, supertype: Supertype) { self.supertype - .borrow_mut() - .insert(read.id, (supertype.clone(), SystemTime::now())); + .insert(supertype.id, (supertype, SystemTime::now())); } /// Exhume (get) [`Supertype`] from the store. /// - pub fn exhume_supertype(&self, id: &Uuid) -> Option>> { - self.supertype - .borrow() - .get(id) - .map(|supertype| supertype.0.clone()) + pub fn exhume_supertype(&self, id: &Uuid) -> Option<&Supertype> { + self.supertype.get(id).map(|supertype| &supertype.0) } /// Exorcise (remove) [`Supertype`] from the store. /// - pub fn exorcise_supertype(&mut self, id: &Uuid) -> Option>> { - self.supertype - .borrow_mut() - .remove(id) - .map(|supertype| supertype.0.clone()) + pub fn exorcise_supertype(&mut self, id: &Uuid) -> Option { + self.supertype.remove(id).map(|supertype| supertype.0) } /// Get an iterator over the internal `HashMap<&Uuid, Supertype>`. /// - pub fn iter_supertype(&self) -> impl Iterator>> + '_ { - let values: Vec>> = self - .supertype - .borrow() - .values() - .map(|supertype| supertype.0.clone()) - .collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_supertype(&self) -> impl Iterator { + self.supertype.values().map(|supertype| &supertype.0) } /// Get the timestamp for Supertype. /// pub fn supertype_timestamp(&self, supertype: &Supertype) -> SystemTime { self.supertype - .borrow() .get(&supertype.id) .map(|supertype| supertype.1) .unwrap_or(SystemTime::now()) @@ -1121,39 +827,32 @@ impl ObjectStore { /// Inter (insert) [`Ty`] into the store. /// - pub fn inter_ty(&mut self, ty: Rc>) { - let read = ty.borrow(); - self.ty - .borrow_mut() - .insert(read.id(), (ty.clone(), SystemTime::now())); + pub fn inter_ty(&mut self, ty: Ty) { + self.ty.insert(ty.id(), (ty, SystemTime::now())); } /// Exhume (get) [`Ty`] from the store. /// - pub fn exhume_ty(&self, id: &Uuid) -> Option>> { - self.ty.borrow().get(id).map(|ty| ty.0.clone()) + pub fn exhume_ty(&self, id: &Uuid) -> Option<&Ty> { + self.ty.get(id).map(|ty| &ty.0) } /// Exorcise (remove) [`Ty`] from the store. /// - pub fn exorcise_ty(&mut self, id: &Uuid) -> Option>> { - self.ty.borrow_mut().remove(id).map(|ty| ty.0.clone()) + pub fn exorcise_ty(&mut self, id: &Uuid) -> Option { + self.ty.remove(id).map(|ty| ty.0) } /// Get an iterator over the internal `HashMap<&Uuid, Ty>`. /// - pub fn iter_ty(&self) -> impl Iterator>> + '_ { - let values: Vec>> = - self.ty.borrow().values().map(|ty| ty.0.clone()).collect(); - let len = values.len(); - (0..len).map(move |i| values[i].clone()) + pub fn iter_ty(&self) -> impl Iterator { + self.ty.values().map(|ty| &ty.0) } /// Get the timestamp for Ty. /// pub fn ty_timestamp(&self, ty: &Ty) -> SystemTime { self.ty - .borrow() .get(&ty.id()) .map(|ty| ty.1) .unwrap_or(SystemTime::now()) @@ -1189,16 +888,13 @@ impl ObjectStore { { let path = path.join("acknowledged_event"); fs::create_dir_all(&path)?; - for acknowledged_event_tuple in self.acknowledged_event.borrow().values() { - let path = path.join(format!("{}.json", acknowledged_event_tuple.0.borrow().id)); + for acknowledged_event_tuple in self.acknowledged_event.values() { + let path = path.join(format!("{}.json", acknowledged_event_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() - != acknowledged_event_tuple.0.borrow().to_owned() - { + let on_disk: (AcknowledgedEvent, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != acknowledged_event_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &acknowledged_event_tuple)?; @@ -1215,7 +911,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.acknowledged_event.borrow().contains_key(&id) { + if !self.acknowledged_event.contains_key(&id) { fs::remove_file(path)?; } } @@ -1226,19 +922,14 @@ impl ObjectStore { { let path = path.join("an_associative_referent"); fs::create_dir_all(&path)?; - for an_associative_referent_tuple in self.an_associative_referent.borrow().values() { - let path = path.join(format!( - "{}.json", - an_associative_referent_tuple.0.borrow().id - )); + for an_associative_referent_tuple in self.an_associative_referent.values() { + let path = path.join(format!("{}.json", an_associative_referent_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = + let on_disk: (AnAssociativeReferent, SystemTime) = serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() - != an_associative_referent_tuple.0.borrow().to_owned() - { + if on_disk.0 != an_associative_referent_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &an_associative_referent_tuple)?; @@ -1255,7 +946,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.an_associative_referent.borrow().contains_key(&id) { + if !self.an_associative_referent.contains_key(&id) { fs::remove_file(path)?; } } @@ -1266,14 +957,13 @@ impl ObjectStore { { let path = path.join("associative"); fs::create_dir_all(&path)?; - for associative_tuple in self.associative.borrow().values() { - let path = path.join(format!("{}.json", associative_tuple.0.borrow().id)); + for associative_tuple in self.associative.values() { + let path = path.join(format!("{}.json", associative_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != associative_tuple.0.borrow().to_owned() { + let on_disk: (Associative, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != associative_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &associative_tuple)?; @@ -1290,7 +980,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.associative.borrow().contains_key(&id) { + if !self.associative.contains_key(&id) { fs::remove_file(path)?; } } @@ -1301,16 +991,14 @@ impl ObjectStore { { let path = path.join("associative_referent"); fs::create_dir_all(&path)?; - for associative_referent_tuple in self.associative_referent.borrow().values() { - let path = path.join(format!("{}.json", associative_referent_tuple.0.borrow().id)); + for associative_referent_tuple in self.associative_referent.values() { + let path = path.join(format!("{}.json", associative_referent_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = + let on_disk: (AssociativeReferent, SystemTime) = serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() - != associative_referent_tuple.0.borrow().to_owned() - { + if on_disk.0 != associative_referent_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &associative_referent_tuple)?; @@ -1327,7 +1015,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.associative_referent.borrow().contains_key(&id) { + if !self.associative_referent.contains_key(&id) { fs::remove_file(path)?; } } @@ -1338,16 +1026,14 @@ impl ObjectStore { { let path = path.join("associative_referrer"); fs::create_dir_all(&path)?; - for associative_referrer_tuple in self.associative_referrer.borrow().values() { - let path = path.join(format!("{}.json", associative_referrer_tuple.0.borrow().id)); + for associative_referrer_tuple in self.associative_referrer.values() { + let path = path.join(format!("{}.json", associative_referrer_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = + let on_disk: (AssociativeReferrer, SystemTime) = serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() - != associative_referrer_tuple.0.borrow().to_owned() - { + if on_disk.0 != associative_referrer_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &associative_referrer_tuple)?; @@ -1364,7 +1050,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.associative_referrer.borrow().contains_key(&id) { + if !self.associative_referrer.contains_key(&id) { fs::remove_file(path)?; } } @@ -1375,14 +1061,13 @@ impl ObjectStore { { let path = path.join("attribute"); fs::create_dir_all(&path)?; - for attribute_tuple in self.attribute.borrow().values() { - let path = path.join(format!("{}.json", attribute_tuple.0.borrow().id)); + for attribute_tuple in self.attribute.values() { + let path = path.join(format!("{}.json", attribute_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != attribute_tuple.0.borrow().to_owned() { + let on_disk: (Attribute, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != attribute_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &attribute_tuple)?; @@ -1399,7 +1084,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.attribute.borrow().contains_key(&id) { + if !self.attribute.contains_key(&id) { fs::remove_file(path)?; } } @@ -1410,14 +1095,13 @@ impl ObjectStore { { let path = path.join("binary"); fs::create_dir_all(&path)?; - for binary_tuple in self.binary.borrow().values() { - let path = path.join(format!("{}.json", binary_tuple.0.borrow().id)); + for binary_tuple in self.binary.values() { + let path = path.join(format!("{}.json", binary_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != binary_tuple.0.borrow().to_owned() { + let on_disk: (Binary, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != binary_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &binary_tuple)?; @@ -1434,7 +1118,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.binary.borrow().contains_key(&id) { + if !self.binary.contains_key(&id) { fs::remove_file(path)?; } } @@ -1445,14 +1129,13 @@ impl ObjectStore { { let path = path.join("cardinality"); fs::create_dir_all(&path)?; - for cardinality_tuple in self.cardinality.borrow().values() { - let path = path.join(format!("{}.json", cardinality_tuple.0.borrow().id())); + for cardinality_tuple in self.cardinality.values() { + let path = path.join(format!("{}.json", cardinality_tuple.0.id())); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != cardinality_tuple.0.borrow().to_owned() { + let on_disk: (Cardinality, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != cardinality_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &cardinality_tuple)?; @@ -1469,7 +1152,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.cardinality.borrow().contains_key(&id) { + if !self.cardinality.contains_key(&id) { fs::remove_file(path)?; } } @@ -1480,14 +1163,13 @@ impl ObjectStore { { let path = path.join("conditionality"); fs::create_dir_all(&path)?; - for conditionality_tuple in self.conditionality.borrow().values() { - let path = path.join(format!("{}.json", conditionality_tuple.0.borrow().id())); + for conditionality_tuple in self.conditionality.values() { + let path = path.join(format!("{}.json", conditionality_tuple.0.id())); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != conditionality_tuple.0.borrow().to_owned() { + let on_disk: (Conditionality, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != conditionality_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &conditionality_tuple)?; @@ -1504,7 +1186,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.conditionality.borrow().contains_key(&id) { + if !self.conditionality.contains_key(&id) { fs::remove_file(path)?; } } @@ -1515,14 +1197,13 @@ impl ObjectStore { { let path = path.join("event"); fs::create_dir_all(&path)?; - for event_tuple in self.event.borrow().values() { - let path = path.join(format!("{}.json", event_tuple.0.borrow().id)); + for event_tuple in self.event.values() { + let path = path.join(format!("{}.json", event_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != event_tuple.0.borrow().to_owned() { + let on_disk: (Event, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != event_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &event_tuple)?; @@ -1539,7 +1220,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.event.borrow().contains_key(&id) { + if !self.event.contains_key(&id) { fs::remove_file(path)?; } } @@ -1550,14 +1231,13 @@ impl ObjectStore { { let path = path.join("external"); fs::create_dir_all(&path)?; - for external_tuple in self.external.borrow().values() { - let path = path.join(format!("{}.json", external_tuple.0.borrow().id)); + for external_tuple in self.external.values() { + let path = path.join(format!("{}.json", external_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != external_tuple.0.borrow().to_owned() { + let on_disk: (External, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != external_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &external_tuple)?; @@ -1574,7 +1254,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.external.borrow().contains_key(&id) { + if !self.external.contains_key(&id) { fs::remove_file(path)?; } } @@ -1585,13 +1265,13 @@ impl ObjectStore { { let path = path.join("isa"); fs::create_dir_all(&path)?; - for isa_tuple in self.isa.borrow().values() { - let path = path.join(format!("{}.json", isa_tuple.0.borrow().id)); + for isa_tuple in self.isa.values() { + let path = path.join(format!("{}.json", isa_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != isa_tuple.0.borrow().to_owned() { + let on_disk: (Isa, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != isa_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &isa_tuple)?; @@ -1608,7 +1288,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.isa.borrow().contains_key(&id) { + if !self.isa.contains_key(&id) { fs::remove_file(path)?; } } @@ -1619,14 +1299,13 @@ impl ObjectStore { { let path = path.join("object"); fs::create_dir_all(&path)?; - for object_tuple in self.object.borrow().values() { - let path = path.join(format!("{}.json", object_tuple.0.borrow().id)); + for object_tuple in self.object.values() { + let path = path.join(format!("{}.json", object_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != object_tuple.0.borrow().to_owned() { + let on_disk: (Object, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != object_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &object_tuple)?; @@ -1643,7 +1322,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.object.borrow().contains_key(&id) { + if !self.object.contains_key(&id) { fs::remove_file(path)?; } } @@ -1654,14 +1333,13 @@ impl ObjectStore { { let path = path.join("referent"); fs::create_dir_all(&path)?; - for referent_tuple in self.referent.borrow().values() { - let path = path.join(format!("{}.json", referent_tuple.0.borrow().id)); + for referent_tuple in self.referent.values() { + let path = path.join(format!("{}.json", referent_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != referent_tuple.0.borrow().to_owned() { + let on_disk: (Referent, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != referent_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &referent_tuple)?; @@ -1678,7 +1356,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.referent.borrow().contains_key(&id) { + if !self.referent.contains_key(&id) { fs::remove_file(path)?; } } @@ -1689,14 +1367,13 @@ impl ObjectStore { { let path = path.join("referrer"); fs::create_dir_all(&path)?; - for referrer_tuple in self.referrer.borrow().values() { - let path = path.join(format!("{}.json", referrer_tuple.0.borrow().id)); + for referrer_tuple in self.referrer.values() { + let path = path.join(format!("{}.json", referrer_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != referrer_tuple.0.borrow().to_owned() { + let on_disk: (Referrer, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != referrer_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &referrer_tuple)?; @@ -1713,7 +1390,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.referrer.borrow().contains_key(&id) { + if !self.referrer.contains_key(&id) { fs::remove_file(path)?; } } @@ -1724,14 +1401,13 @@ impl ObjectStore { { let path = path.join("relationship"); fs::create_dir_all(&path)?; - for relationship_tuple in self.relationship.borrow().values() { - let path = path.join(format!("{}.json", relationship_tuple.0.borrow().id())); + for relationship_tuple in self.relationship.values() { + let path = path.join(format!("{}.json", relationship_tuple.0.id())); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != relationship_tuple.0.borrow().to_owned() { + let on_disk: (Relationship, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != relationship_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &relationship_tuple)?; @@ -1748,7 +1424,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.relationship.borrow().contains_key(&id) { + if !self.relationship.contains_key(&id) { fs::remove_file(path)?; } } @@ -1759,14 +1435,13 @@ impl ObjectStore { { let path = path.join("state"); fs::create_dir_all(&path)?; - for state_tuple in self.state.borrow().values() { - let path = path.join(format!("{}.json", state_tuple.0.borrow().id)); + for state_tuple in self.state.values() { + let path = path.join(format!("{}.json", state_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != state_tuple.0.borrow().to_owned() { + let on_disk: (State, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != state_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &state_tuple)?; @@ -1783,7 +1458,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.state.borrow().contains_key(&id) { + if !self.state.contains_key(&id) { fs::remove_file(path)?; } } @@ -1794,14 +1469,13 @@ impl ObjectStore { { let path = path.join("subtype"); fs::create_dir_all(&path)?; - for subtype_tuple in self.subtype.borrow().values() { - let path = path.join(format!("{}.json", subtype_tuple.0.borrow().id)); + for subtype_tuple in self.subtype.values() { + let path = path.join(format!("{}.json", subtype_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != subtype_tuple.0.borrow().to_owned() { + let on_disk: (Subtype, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != subtype_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &subtype_tuple)?; @@ -1818,7 +1492,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.subtype.borrow().contains_key(&id) { + if !self.subtype.contains_key(&id) { fs::remove_file(path)?; } } @@ -1829,14 +1503,13 @@ impl ObjectStore { { let path = path.join("supertype"); fs::create_dir_all(&path)?; - for supertype_tuple in self.supertype.borrow().values() { - let path = path.join(format!("{}.json", supertype_tuple.0.borrow().id)); + for supertype_tuple in self.supertype.values() { + let path = path.join(format!("{}.json", supertype_tuple.0.id)); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != supertype_tuple.0.borrow().to_owned() { + let on_disk: (Supertype, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != supertype_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &supertype_tuple)?; @@ -1853,7 +1526,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.supertype.borrow().contains_key(&id) { + if !self.supertype.contains_key(&id) { fs::remove_file(path)?; } } @@ -1864,13 +1537,13 @@ impl ObjectStore { { let path = path.join("ty"); fs::create_dir_all(&path)?; - for ty_tuple in self.ty.borrow().values() { - let path = path.join(format!("{}.json", ty_tuple.0.borrow().id())); + for ty_tuple in self.ty.values() { + let path = path.join(format!("{}.json", ty_tuple.0.id())); if path.exists() { let file = fs::File::open(&path)?; let reader = io::BufReader::new(file); - let on_disk: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - if on_disk.0.borrow().to_owned() != ty_tuple.0.borrow().to_owned() { + let on_disk: (Ty, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != ty_tuple.0 { let file = fs::File::create(path)?; let mut writer = io::BufWriter::new(file); serde_json::to_writer_pretty(&mut writer, &ty_tuple)?; @@ -1887,7 +1560,7 @@ impl ObjectStore { let file_name = path.file_name().unwrap().to_str().unwrap(); let id = file_name.split('.').next().unwrap(); if let Ok(id) = Uuid::parse_str(id) { - if !self.ty.borrow().contains_key(&id) { + if !self.ty.contains_key(&id) { fs::remove_file(path)?; } } @@ -1919,7 +1592,7 @@ impl ObjectStore { let path = path.as_ref(); let path = path.join("sarzak.json"); - let store = Self::new(); + let mut store = Self::new(); // Load Acknowledged Event. { @@ -1930,12 +1603,11 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let acknowledged_event: (Rc>, SystemTime) = + let acknowledged_event: (AcknowledgedEvent, SystemTime) = serde_json::from_reader(reader)?; store .acknowledged_event - .borrow_mut() - .insert(acknowledged_event.0.borrow().id, acknowledged_event.clone()); + .insert(acknowledged_event.0.id, acknowledged_event); } } @@ -1948,12 +1620,11 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let an_associative_referent: (Rc>, SystemTime) = + let an_associative_referent: (AnAssociativeReferent, SystemTime) = serde_json::from_reader(reader)?; - store.an_associative_referent.borrow_mut().insert( - an_associative_referent.0.borrow().id, - an_associative_referent.clone(), - ); + store + .an_associative_referent + .insert(an_associative_referent.0.id, an_associative_referent); } } @@ -1966,12 +1637,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let associative: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .associative - .borrow_mut() - .insert(associative.0.borrow().id, associative.clone()); + let associative: (Associative, SystemTime) = serde_json::from_reader(reader)?; + store.associative.insert(associative.0.id, associative); } } @@ -1984,12 +1651,11 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let associative_referent: (Rc>, SystemTime) = + let associative_referent: (AssociativeReferent, SystemTime) = serde_json::from_reader(reader)?; - store.associative_referent.borrow_mut().insert( - associative_referent.0.borrow().id, - associative_referent.clone(), - ); + store + .associative_referent + .insert(associative_referent.0.id, associative_referent); } } @@ -2002,12 +1668,11 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let associative_referrer: (Rc>, SystemTime) = + let associative_referrer: (AssociativeReferrer, SystemTime) = serde_json::from_reader(reader)?; - store.associative_referrer.borrow_mut().insert( - associative_referrer.0.borrow().id, - associative_referrer.clone(), - ); + store + .associative_referrer + .insert(associative_referrer.0.id, associative_referrer); } } @@ -2020,12 +1685,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let attribute: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .attribute - .borrow_mut() - .insert(attribute.0.borrow().id, attribute.clone()); + let attribute: (Attribute, SystemTime) = serde_json::from_reader(reader)?; + store.attribute.insert(attribute.0.id, attribute); } } @@ -2038,11 +1699,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let binary: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store - .binary - .borrow_mut() - .insert(binary.0.borrow().id, binary.clone()); + let binary: (Binary, SystemTime) = serde_json::from_reader(reader)?; + store.binary.insert(binary.0.id, binary); } } @@ -2055,12 +1713,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let cardinality: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .cardinality - .borrow_mut() - .insert(cardinality.0.borrow().id(), cardinality.clone()); + let cardinality: (Cardinality, SystemTime) = serde_json::from_reader(reader)?; + store.cardinality.insert(cardinality.0.id(), cardinality); } } @@ -2073,12 +1727,10 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let conditionality: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; + let conditionality: (Conditionality, SystemTime) = serde_json::from_reader(reader)?; store .conditionality - .borrow_mut() - .insert(conditionality.0.borrow().id(), conditionality.clone()); + .insert(conditionality.0.id(), conditionality); } } @@ -2091,11 +1743,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let event: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store - .event - .borrow_mut() - .insert(event.0.borrow().id, event.clone()); + let event: (Event, SystemTime) = serde_json::from_reader(reader)?; + store.event.insert(event.0.id, event); } } @@ -2108,12 +1757,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let external: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .external - .borrow_mut() - .insert(external.0.borrow().id, external.clone()); + let external: (External, SystemTime) = serde_json::from_reader(reader)?; + store.external.insert(external.0.id, external); } } @@ -2126,11 +1771,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let isa: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store - .isa - .borrow_mut() - .insert(isa.0.borrow().id, isa.clone()); + let isa: (Isa, SystemTime) = serde_json::from_reader(reader)?; + store.isa.insert(isa.0.id, isa); } } @@ -2143,15 +1785,11 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let object: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store.object_id_by_name.borrow_mut().insert( - object.0.borrow().name.to_upper_camel_case(), - (object.0.borrow().id, object.1), - ); + let object: (Object, SystemTime) = serde_json::from_reader(reader)?; store - .object - .borrow_mut() - .insert(object.0.borrow().id, object.clone()); + .object_id_by_name + .insert(object.0.name.to_upper_camel_case(), (object.0.id, object.1)); + store.object.insert(object.0.id, object); } } @@ -2164,12 +1802,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let referent: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .referent - .borrow_mut() - .insert(referent.0.borrow().id, referent.clone()); + let referent: (Referent, SystemTime) = serde_json::from_reader(reader)?; + store.referent.insert(referent.0.id, referent); } } @@ -2182,12 +1816,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let referrer: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .referrer - .borrow_mut() - .insert(referrer.0.borrow().id, referrer.clone()); + let referrer: (Referrer, SystemTime) = serde_json::from_reader(reader)?; + store.referrer.insert(referrer.0.id, referrer); } } @@ -2200,12 +1830,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let relationship: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .relationship - .borrow_mut() - .insert(relationship.0.borrow().id(), relationship.clone()); + let relationship: (Relationship, SystemTime) = serde_json::from_reader(reader)?; + store.relationship.insert(relationship.0.id(), relationship); } } @@ -2218,11 +1844,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let state: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store - .state - .borrow_mut() - .insert(state.0.borrow().id, state.clone()); + let state: (State, SystemTime) = serde_json::from_reader(reader)?; + store.state.insert(state.0.id, state); } } @@ -2235,11 +1858,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let subtype: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store - .subtype - .borrow_mut() - .insert(subtype.0.borrow().id, subtype.clone()); + let subtype: (Subtype, SystemTime) = serde_json::from_reader(reader)?; + store.subtype.insert(subtype.0.id, subtype); } } @@ -2252,12 +1872,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let supertype: (Rc>, SystemTime) = - serde_json::from_reader(reader)?; - store - .supertype - .borrow_mut() - .insert(supertype.0.borrow().id, supertype.clone()); + let supertype: (Supertype, SystemTime) = serde_json::from_reader(reader)?; + store.supertype.insert(supertype.0.id, supertype); } } @@ -2270,8 +1886,8 @@ impl ObjectStore { let path = entry.path(); let file = fs::File::open(path)?; let reader = io::BufReader::new(file); - let ty: (Rc>, SystemTime) = serde_json::from_reader(reader)?; - store.ty.borrow_mut().insert(ty.0.borrow().id(), ty.clone()); + let ty: (Ty, SystemTime) = serde_json::from_reader(reader)?; + store.ty.insert(ty.0.id(), ty); } } diff --git a/src/v2/sarzak_single/types/acknowledged_event.rs b/src/v2/sarzak_single/types/acknowledged_event.rs index f9fcab51..32f87fbb 100644 --- a/src/v2/sarzak_single/types/acknowledged_event.rs +++ b/src/v2/sarzak_single/types/acknowledged_event.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"acknowledged_event-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"acknowledged_event-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::event::Event; @@ -32,29 +30,29 @@ impl AcknowledgedEvent { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"acknowledged_event-struct-impl-new"}}} /// Inter a new 'Acknowledged Event' in the store, and return it's `id`. pub fn new( - event_id: &Rc>, - state_id: &Rc>, + event_id: &Event, + state_id: &State, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> AcknowledgedEvent { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(AcknowledgedEvent { + let new = AcknowledgedEvent { id, - event_id: event_id.borrow().id, - state_id: state_id.borrow().id, - })); + event_id: event_id.id, + state_id: state_id.id, + }; store.inter_acknowledged_event(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"acknowledged_event-struct-impl-nav-forward-assoc-to-event_id"}}} /// Navigate to [`Event`] across R20(1-*) - pub fn r20_event<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r20_event<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Event> { vec![store.exhume_event(&self.event_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"acknowledged_event-struct-impl-nav-forward-assoc-to-state_id"}}} /// Navigate to [`State`] across R20(1-*) - pub fn r20_state<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r20_state<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&State> { vec![store.exhume_state(&self.state_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/an_associative_referent.rs b/src/v2/sarzak_single/types/an_associative_referent.rs index a2b05b5f..9d54991d 100644 --- a/src/v2/sarzak_single/types/an_associative_referent.rs +++ b/src/v2/sarzak_single/types/an_associative_referent.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"an_associative_referent-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"an_associative_referent-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::associative::Associative; @@ -28,27 +26,24 @@ impl AnAssociativeReferent { /// Inter a new 'An Associative Referent' in the store, and return it's `id`. pub fn new( referential_attribute: String, - associative: &Rc>, - referent: &Rc>, + associative: &Associative, + referent: &AssociativeReferent, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> AnAssociativeReferent { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(AnAssociativeReferent { + let new = AnAssociativeReferent { id, referential_attribute, - associative: associative.borrow().id, - referent: referent.borrow().id, - })); + associative: associative.id, + referent: referent.id, + }; store.inter_an_associative_referent(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"an_associative_referent-struct-impl-nav-forward-assoc-to-associative"}}} /// Navigate to [`Associative`] across R22(1-*) - pub fn r22_associative<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r22_associative<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Associative> { vec![store.exhume_associative(&self.associative).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -57,7 +52,7 @@ impl AnAssociativeReferent { pub fn r22_associative_referent<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferent> { vec![store.exhume_associative_referent(&self.referent).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/associative.rs b/src/v2/sarzak_single/types/associative.rs index 2297b740..759a37f2 100644 --- a/src/v2/sarzak_single/types/associative.rs +++ b/src/v2/sarzak_single/types/associative.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"associative-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::an_associative_referent::AnAssociativeReferent; @@ -27,15 +25,15 @@ impl Associative { /// Inter a new 'Associative' in the store, and return it's `id`. pub fn new( number: i64, - from: &Rc>, + from: &AssociativeReferrer, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> Associative { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Associative { + let new = Associative { id, number, - from: from.borrow().id, - })); + from: from.id, + }; store.inter_associative(new.clone()); new } @@ -45,7 +43,7 @@ impl Associative { pub fn r21_associative_referrer<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferrer> { vec![store.exhume_associative_referrer(&self.from).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -54,21 +52,16 @@ impl Associative { pub fn r22_an_associative_referent<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AnAssociativeReferent> { store .iter_an_associative_referent() - .filter(|an_associative_referent| { - an_associative_referent.borrow().associative == self.id - }) + .filter(|an_associative_referent| an_associative_referent.associative == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative-impl-nav-subtype-to-supertype-relationship"}}} // Navigate to [`Relationship`] across R4(isa) - pub fn r4_relationship<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r4_relationship<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Relationship> { vec![store.exhume_relationship(&self.id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/associative_referent.rs b/src/v2/sarzak_single/types/associative_referent.rs index 4a79afc3..d8f58f00 100644 --- a/src/v2/sarzak_single/types/associative_referent.rs +++ b/src/v2/sarzak_single/types/associative_referent.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"associative_referent-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referent-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::an_associative_referent::AnAssociativeReferent; @@ -39,44 +37,38 @@ impl AssociativeReferent { /// Inter a new 'Associative Referent' in the store, and return it's `id`. pub fn new( description: String, - cardinality: &Rc>, - conditionality: &Rc>, - obj_id: &Rc>, + cardinality: &Cardinality, + conditionality: &Conditionality, + obj_id: &Object, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> AssociativeReferent { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(AssociativeReferent { + let new = AssociativeReferent { description, id, - cardinality: cardinality.borrow().id(), - conditionality: conditionality.borrow().id(), - obj_id: obj_id.borrow().id, - })); + cardinality: cardinality.id(), + conditionality: conditionality.id(), + obj_id: obj_id.id, + }; store.inter_associative_referent(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referent-struct-impl-nav-forward-to-cardinality"}}} /// Navigate to [`Cardinality`] across R88(1-*) - pub fn r88_cardinality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r88_cardinality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Cardinality> { vec![store.exhume_cardinality(&self.cardinality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referent-struct-impl-nav-forward-to-conditionality"}}} /// Navigate to [`Conditionality`] across R77(1-*) - pub fn r77_conditionality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r77_conditionality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Conditionality> { vec![store.exhume_conditionality(&self.conditionality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referent-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R25(1-*) - pub fn r25_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r25_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -85,10 +77,10 @@ impl AssociativeReferent { pub fn r22_an_associative_referent<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AnAssociativeReferent> { vec![store .iter_an_associative_referent() - .find(|an_associative_referent| an_associative_referent.borrow().referent == self.id) + .find(|an_associative_referent| an_associative_referent.referent == self.id) .unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/associative_referrer.rs b/src/v2/sarzak_single/types/associative_referrer.rs index 21213491..0a66e444 100644 --- a/src/v2/sarzak_single/types/associative_referrer.rs +++ b/src/v2/sarzak_single/types/associative_referrer.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"associative_referrer-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referrer-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::associative::Associative; @@ -34,44 +32,38 @@ impl AssociativeReferrer { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referrer-struct-impl-new"}}} /// Inter a new 'Associative Referrer' in the store, and return it's `id`. pub fn new( - cardinality: &Rc>, - obj_id: &Rc>, + cardinality: &Cardinality, + obj_id: &Object, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> AssociativeReferrer { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(AssociativeReferrer { + let new = AssociativeReferrer { id, - cardinality: cardinality.borrow().id(), - obj_id: obj_id.borrow().id, - })); + cardinality: cardinality.id(), + obj_id: obj_id.id, + }; store.inter_associative_referrer(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referrer-struct-impl-nav-forward-to-cardinality"}}} /// Navigate to [`Cardinality`] across R89(1-*) - pub fn r89_cardinality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r89_cardinality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Cardinality> { vec![store.exhume_cardinality(&self.cardinality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referrer-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R26(1-*) - pub fn r26_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r26_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"associative_referrer-struct-impl-nav-backward-one-to-associative"}}} /// Navigate to [`Associative`] across R21(1-1) - pub fn r21_associative<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r21_associative<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Associative> { vec![store .iter_associative() - .find(|associative| associative.borrow().from == self.id) + .find(|associative| associative.from == self.id) .unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/attribute.rs b/src/v2/sarzak_single/types/attribute.rs index 2657a46a..728bcbeb 100644 --- a/src/v2/sarzak_single/types/attribute.rs +++ b/src/v2/sarzak_single/types/attribute.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"attribute-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"attribute-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::object::Object; @@ -32,32 +30,27 @@ pub struct Attribute { impl Attribute { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"attribute-struct-impl-new"}}} /// Inter a new 'Attribute' in the store, and return it's `id`. - pub fn new( - name: String, - obj_id: &Rc>, - ty: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { + pub fn new(name: String, obj_id: &Object, ty: &Ty, store: &mut SarzakSingleStore) -> Attribute { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Attribute { + let new = Attribute { id, name, - obj_id: obj_id.borrow().id, - ty: ty.borrow().id(), - })); + obj_id: obj_id.id, + ty: ty.id(), + }; store.inter_attribute(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"attribute-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R1(1-*) - pub fn r1_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r1_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"attribute-struct-impl-nav-forward-to-ty"}}} /// Navigate to [`Ty`] across R2(1-*) - pub fn r2_ty<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r2_ty<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Ty> { vec![store.exhume_ty(&self.ty).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/binary.rs b/src/v2/sarzak_single/types/binary.rs index 99fc72f6..6c4f8cd8 100644 --- a/src/v2/sarzak_single/types/binary.rs +++ b/src/v2/sarzak_single/types/binary.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"binary-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::referent::Referent; @@ -42,39 +40,36 @@ impl Binary { /// Inter a new 'Binary' in the store, and return it's `id`. pub fn new( number: i64, - from: &Rc>, - to: &Rc>, + from: &Referrer, + to: &Referent, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> Binary { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Binary { + let new = Binary { id, number, - from: from.borrow().id, - to: to.borrow().id, - })); + from: from.id, + to: to.id, + }; store.inter_binary(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary-struct-impl-nav-forward-to-from"}}} /// Navigate to [`Referrer`] across R6(1-*) - pub fn r6_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r6_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referrer> { vec![store.exhume_referrer(&self.from).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary-struct-impl-nav-forward-to-to"}}} /// Navigate to [`Referent`] across R5(1-*) - pub fn r5_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r5_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referent> { vec![store.exhume_referent(&self.to).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"binary-impl-nav-subtype-to-supertype-relationship"}}} // Navigate to [`Relationship`] across R4(isa) - pub fn r4_relationship<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r4_relationship<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Relationship> { vec![store.exhume_relationship(&self.id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/cardinality.rs b/src/v2/sarzak_single/types/cardinality.rs index c9173ae6..62e17560 100644 --- a/src/v2/sarzak_single/types/cardinality.rs +++ b/src/v2/sarzak_single/types/cardinality.rs @@ -8,8 +8,6 @@ use crate::v2::sarzak_single::types::one::ONE; use crate::v2::sarzak_single::types::referent::Referent; use crate::v2::sarzak_single::types::referrer::Referrer; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -24,15 +22,15 @@ pub enum Cardinality { impl Cardinality { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"cardinality-new-impl"}}} /// Create a new instance of Cardinality::Many - pub fn new_many(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_cardinality(&MANY).unwrap() + pub fn new_many() -> Self { + // This is already in the store, see associated function `new` above. + Self::Many(MANY) } /// Create a new instance of Cardinality::One - pub fn new_one(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_cardinality(&ONE).unwrap() + pub fn new_one() -> Self { + // This is already in the store, see associated function `new` above. + Self::One(ONE) } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -49,10 +47,10 @@ impl Cardinality { pub fn r88_associative_referent<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferent> { store .iter_associative_referent() - .filter(|associative_referent| associative_referent.borrow().cardinality == self.id()) + .filter(|associative_referent| associative_referent.cardinality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -61,28 +59,28 @@ impl Cardinality { pub fn r89_associative_referrer<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferrer> { store .iter_associative_referrer() - .filter(|associative_referrer| associative_referrer.borrow().cardinality == self.id()) + .filter(|associative_referrer| associative_referrer.cardinality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"cardinality-struct-impl-nav-backward-1_M-to-referent"}}} /// Navigate to [`Referent`] across R8(1-M) - pub fn r8_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r8_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referent> { store .iter_referent() - .filter(|referent| referent.borrow().cardinality == self.id()) + .filter(|referent| referent.cardinality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"cardinality-struct-impl-nav-backward-1_M-to-referrer"}}} /// Navigate to [`Referrer`] across R9(1-M) - pub fn r9_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r9_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referrer> { store .iter_referrer() - .filter(|referrer| referrer.borrow().cardinality == self.id()) + .filter(|referrer| referrer.cardinality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/conditionality.rs b/src/v2/sarzak_single/types/conditionality.rs index f3f91db6..c3c6964d 100644 --- a/src/v2/sarzak_single/types/conditionality.rs +++ b/src/v2/sarzak_single/types/conditionality.rs @@ -7,8 +7,6 @@ use crate::v2::sarzak_single::types::referent::Referent; use crate::v2::sarzak_single::types::referrer::Referrer; use crate::v2::sarzak_single::types::unconditional::UNCONDITIONAL; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -23,15 +21,15 @@ pub enum Conditionality { impl Conditionality { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"conditionality-new-impl"}}} /// Create a new instance of Conditionality::Conditional - pub fn new_conditional(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_conditionality(&CONDITIONAL).unwrap() + pub fn new_conditional() -> Self { + // This is already in the store, see associated function `new` above. + Self::Conditional(CONDITIONAL) } /// Create a new instance of Conditionality::Unconditional - pub fn new_unconditional(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_conditionality(&UNCONDITIONAL).unwrap() + pub fn new_unconditional() -> Self { + // This is already in the store, see associated function `new` above. + Self::Unconditional(UNCONDITIONAL) } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -48,30 +46,28 @@ impl Conditionality { pub fn r77_associative_referent<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferent> { store .iter_associative_referent() - .filter(|associative_referent| { - associative_referent.borrow().conditionality == self.id() - }) + .filter(|associative_referent| associative_referent.conditionality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"conditionality-struct-impl-nav-backward-1_M-to-referent"}}} /// Navigate to [`Referent`] across R12(1-M) - pub fn r12_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r12_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referent> { store .iter_referent() - .filter(|referent| referent.borrow().conditionality == self.id()) + .filter(|referent| referent.conditionality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"conditionality-struct-impl-nav-backward-1_M-to-referrer"}}} /// Navigate to [`Referrer`] across R11(1-M) - pub fn r11_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r11_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referrer> { store .iter_referrer() - .filter(|referrer| referrer.borrow().conditionality == self.id()) + .filter(|referrer| referrer.conditionality == self.id()) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/event.rs b/src/v2/sarzak_single/types/event.rs index 292c9b32..cf57a895 100644 --- a/src/v2/sarzak_single/types/event.rs +++ b/src/v2/sarzak_single/types/event.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"event-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"event-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::acknowledged_event::AcknowledgedEvent; @@ -29,24 +27,20 @@ pub struct Event { impl Event { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"event-struct-impl-new"}}} /// Inter a new 'Event' in the store, and return it's `id`. - pub fn new( - name: String, - obj_id: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { + pub fn new(name: String, obj_id: &Object, store: &mut SarzakSingleStore) -> Event { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Event { + let new = Event { id, name, - obj_id: obj_id.borrow().id, - })); + obj_id: obj_id.id, + }; store.inter_event(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"event-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R19(1-*) - pub fn r19_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r19_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -55,10 +49,10 @@ impl Event { pub fn r20_acknowledged_event<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AcknowledgedEvent> { store .iter_acknowledged_event() - .filter(|acknowledged_event| acknowledged_event.borrow().event_id == self.id) + .filter(|acknowledged_event| acknowledged_event.event_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/external.rs b/src/v2/sarzak_single/types/external.rs index 9a93204c..e1508f6f 100644 --- a/src/v2/sarzak_single/types/external.rs +++ b/src/v2/sarzak_single/types/external.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"external-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"external-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::ty::Ty; @@ -49,21 +47,21 @@ impl External { name: String, x_path: String, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> External { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(External { + let new = External { ctor, id, name, x_path, - })); + }; store.inter_external(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"external-impl-nav-subtype-to-supertype-ty"}}} // Navigate to [`Ty`] across R3(isa) - pub fn r3_ty<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r3_ty<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Ty> { vec![store.exhume_ty(&self.id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/isa.rs b/src/v2/sarzak_single/types/isa.rs index 74830317..588fedc6 100644 --- a/src/v2/sarzak_single/types/isa.rs +++ b/src/v2/sarzak_single/types/isa.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"isa-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"isa-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::relationship::Relationship; @@ -25,45 +23,35 @@ pub struct Isa { impl Isa { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"isa-struct-impl-new"}}} /// Inter a new 'Isa' in the store, and return it's `id`. - pub fn new( - number: i64, - supertype: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { + pub fn new(number: i64, supertype: &Supertype, store: &mut SarzakSingleStore) -> Isa { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Isa { + let new = Isa { id, number, - supertype: supertype.borrow().id, - })); + supertype: supertype.id, + }; store.inter_isa(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"isa-struct-impl-nav-forward-to-supertype"}}} /// Navigate to [`Supertype`] across R13(1-*) - pub fn r13_supertype<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r13_supertype<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Supertype> { vec![store.exhume_supertype(&self.supertype).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"isa-struct-impl-nav-backward-1_M-to-subtype"}}} /// Navigate to [`Subtype`] across R27(1-M) - pub fn r27_subtype<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r27_subtype<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Subtype> { store .iter_subtype() - .filter(|subtype| subtype.borrow().isa == self.id) + .filter(|subtype| subtype.isa == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"isa-impl-nav-subtype-to-supertype-relationship"}}} // Navigate to [`Relationship`] across R4(isa) - pub fn r4_relationship<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r4_relationship<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Relationship> { vec![store.exhume_relationship(&self.id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/object.rs b/src/v2/sarzak_single/types/object.rs index ba05459d..ab3b4e8f 100644 --- a/src/v2/sarzak_single/types/object.rs +++ b/src/v2/sarzak_single/types/object.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"object-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::associative_referent::AssociativeReferent; @@ -48,14 +46,14 @@ impl Object { key_letters: String, name: String, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> Object { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Object { + let new = Object { description, id, key_letters, name, - })); + }; store.inter_object(new.clone()); new } @@ -65,10 +63,10 @@ impl Object { pub fn r25_associative_referent<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferent> { store .iter_associative_referent() - .filter(|associative_referent| associative_referent.borrow().obj_id == self.id) + .filter(|associative_referent| associative_referent.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -77,82 +75,79 @@ impl Object { pub fn r26_associative_referrer<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AssociativeReferrer> { store .iter_associative_referrer() - .filter(|associative_referrer| associative_referrer.borrow().obj_id == self.id) + .filter(|associative_referrer| associative_referrer.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-attribute"}}} /// Navigate to [`Attribute`] across R1(1-M) - pub fn r1_attribute<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r1_attribute<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Attribute> { store .iter_attribute() - .filter(|attribute| attribute.borrow().obj_id == self.id) + .filter(|attribute| attribute.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-event"}}} /// Navigate to [`Event`] across R19(1-M) - pub fn r19_event<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r19_event<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Event> { store .iter_event() - .filter(|event| event.borrow().obj_id == self.id) + .filter(|event| event.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-referent"}}} /// Navigate to [`Referent`] across R16(1-M) - pub fn r16_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r16_referent<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referent> { store .iter_referent() - .filter(|referent| referent.borrow().obj_id == self.id) + .filter(|referent| referent.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-referrer"}}} /// Navigate to [`Referrer`] across R17(1-M) - pub fn r17_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r17_referrer<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Referrer> { store .iter_referrer() - .filter(|referrer| referrer.borrow().obj_id == self.id) + .filter(|referrer| referrer.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-state"}}} /// Navigate to [`State`] across R18(1-M) - pub fn r18_state<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r18_state<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&State> { store .iter_state() - .filter(|state| state.borrow().obj_id == self.id) + .filter(|state| state.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-subtype"}}} /// Navigate to [`Subtype`] across R15(1-M) - pub fn r15_subtype<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r15_subtype<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Subtype> { store .iter_subtype() - .filter(|subtype| subtype.borrow().obj_id == self.id) + .filter(|subtype| subtype.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-struct-impl-nav-backward-1_M-to-supertype"}}} /// Navigate to [`Supertype`] across R14(1-M) - pub fn r14_supertype<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r14_supertype<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Supertype> { store .iter_supertype() - .filter(|supertype| supertype.borrow().obj_id == self.id) + .filter(|supertype| supertype.obj_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object-impl-nav-subtype-to-supertype-ty"}}} // Navigate to [`Ty`] across R3(isa) - pub fn r3_ty<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r3_ty<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Ty> { vec![store.exhume_ty(&self.id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/referent.rs b/src/v2/sarzak_single/types/referent.rs index 8c3604ee..7e4f1f52 100644 --- a/src/v2/sarzak_single/types/referent.rs +++ b/src/v2/sarzak_single/types/referent.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"referent-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referent-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::binary::Binary; @@ -36,53 +34,47 @@ impl Referent { /// Inter a new 'Referent' in the store, and return it's `id`. pub fn new( description: String, - cardinality: &Rc>, - conditionality: &Rc>, - obj_id: &Rc>, + cardinality: &Cardinality, + conditionality: &Conditionality, + obj_id: &Object, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> Referent { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Referent { + let new = Referent { description, id, - cardinality: cardinality.borrow().id(), - conditionality: conditionality.borrow().id(), - obj_id: obj_id.borrow().id, - })); + cardinality: cardinality.id(), + conditionality: conditionality.id(), + obj_id: obj_id.id, + }; store.inter_referent(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referent-struct-impl-nav-forward-to-cardinality"}}} /// Navigate to [`Cardinality`] across R8(1-*) - pub fn r8_cardinality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r8_cardinality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Cardinality> { vec![store.exhume_cardinality(&self.cardinality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referent-struct-impl-nav-forward-to-conditionality"}}} /// Navigate to [`Conditionality`] across R12(1-*) - pub fn r12_conditionality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r12_conditionality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Conditionality> { vec![store.exhume_conditionality(&self.conditionality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referent-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R16(1-*) - pub fn r16_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r16_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referent-struct-impl-nav-backward-one-to-binary"}}} /// Navigate to [`Binary`] across R5(1-1) - pub fn r5_binary<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r5_binary<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Binary> { vec![store .iter_binary() - .find(|binary| binary.borrow().to == self.id) + .find(|binary| binary.to == self.id) .unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/referrer.rs b/src/v2/sarzak_single/types/referrer.rs index e8950bf5..1f7dc2ca 100644 --- a/src/v2/sarzak_single/types/referrer.rs +++ b/src/v2/sarzak_single/types/referrer.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"referrer-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referrer-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::binary::Binary; @@ -39,54 +37,48 @@ impl Referrer { pub fn new( description: String, referential_attribute: String, - cardinality: &Rc>, - conditionality: &Rc>, - obj_id: &Rc>, + cardinality: &Cardinality, + conditionality: &Conditionality, + obj_id: &Object, store: &mut SarzakSingleStore, - ) -> Rc> { + ) -> Referrer { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Referrer { + let new = Referrer { description, id, referential_attribute, - cardinality: cardinality.borrow().id(), - conditionality: conditionality.borrow().id(), - obj_id: obj_id.borrow().id, - })); + cardinality: cardinality.id(), + conditionality: conditionality.id(), + obj_id: obj_id.id, + }; store.inter_referrer(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referrer-struct-impl-nav-forward-to-cardinality"}}} /// Navigate to [`Cardinality`] across R9(1-*) - pub fn r9_cardinality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r9_cardinality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Cardinality> { vec![store.exhume_cardinality(&self.cardinality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referrer-struct-impl-nav-forward-to-conditionality"}}} /// Navigate to [`Conditionality`] across R11(1-*) - pub fn r11_conditionality<'a>( - &'a self, - store: &'a SarzakSingleStore, - ) -> Vec>> { + pub fn r11_conditionality<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Conditionality> { vec![store.exhume_conditionality(&self.conditionality).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referrer-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R17(1-*) - pub fn r17_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r17_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"referrer-struct-impl-nav-backward-one-to-binary"}}} /// Navigate to [`Binary`] across R6(1-1) - pub fn r6_binary<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r6_binary<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Binary> { vec![store .iter_binary() - .find(|binary| binary.borrow().from == self.id) + .find(|binary| binary.from == self.id) .unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/relationship.rs b/src/v2/sarzak_single/types/relationship.rs index 4774d97f..b83470ed 100644 --- a/src/v2/sarzak_single/types/relationship.rs +++ b/src/v2/sarzak_single/types/relationship.rs @@ -5,8 +5,6 @@ use crate::v2::sarzak_single::types::associative::Associative; use crate::v2::sarzak_single::types::binary::Binary; use crate::v2::sarzak_single::types::isa::Isa; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -33,45 +31,24 @@ pub enum Relationship { impl Relationship { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"relationship-new-impl"}}} /// Create a new instance of Relationship::Associative - pub fn new_associative( - associative: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { - let id = associative.borrow().id; - if let Some(associative) = store.exhume_relationship(&id) { - associative - } else { - let new = Rc::new(RefCell::new(Self::Associative(id))); - store.inter_relationship(new.clone()); - new - } + pub fn new_associative(associative: &Associative, store: &mut SarzakSingleStore) -> Self { + let new = Self::Associative(associative.id); + store.inter_relationship(new.clone()); + new } // wtf? /// Create a new instance of Relationship::Binary - pub fn new_binary( - binary: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { - let id = binary.borrow().id; - if let Some(binary) = store.exhume_relationship(&id) { - binary - } else { - let new = Rc::new(RefCell::new(Self::Binary(id))); - store.inter_relationship(new.clone()); - new - } + pub fn new_binary(binary: &Binary, store: &mut SarzakSingleStore) -> Self { + let new = Self::Binary(binary.id); + store.inter_relationship(new.clone()); + new } // wtf? /// Create a new instance of Relationship::Isa - pub fn new_isa(isa: &Rc>, store: &mut SarzakSingleStore) -> Rc> { - let id = isa.borrow().id; - if let Some(isa) = store.exhume_relationship(&id) { - isa - } else { - let new = Rc::new(RefCell::new(Self::Isa(id))); - store.inter_relationship(new.clone()); - new - } + pub fn new_isa(isa: &Isa, store: &mut SarzakSingleStore) -> Self { + let new = Self::Isa(isa.id); + store.inter_relationship(new.clone()); + new } // wtf? // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/state.rs b/src/v2/sarzak_single/types/state.rs index 546c54fc..f0b5e8d7 100644 --- a/src/v2/sarzak_single/types/state.rs +++ b/src/v2/sarzak_single/types/state.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"state-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"state-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::acknowledged_event::AcknowledgedEvent; @@ -28,24 +26,20 @@ pub struct State { impl State { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"state-struct-impl-new"}}} /// Inter a new 'State' in the store, and return it's `id`. - pub fn new( - name: String, - obj_id: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { + pub fn new(name: String, obj_id: &Object, store: &mut SarzakSingleStore) -> State { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(State { + let new = State { id, name, - obj_id: obj_id.borrow().id, - })); + obj_id: obj_id.id, + }; store.inter_state(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"state-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R18(1-*) - pub fn r18_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r18_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -54,10 +48,10 @@ impl State { pub fn r20_acknowledged_event<'a>( &'a self, store: &'a SarzakSingleStore, - ) -> Vec>> { + ) -> Vec<&AcknowledgedEvent> { store .iter_acknowledged_event() - .filter(|acknowledged_event| acknowledged_event.borrow().state_id == self.id) + .filter(|acknowledged_event| acknowledged_event.state_id == self.id) .collect() } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/subtype.rs b/src/v2/sarzak_single/types/subtype.rs index ccae3bfb..69705eca 100644 --- a/src/v2/sarzak_single/types/subtype.rs +++ b/src/v2/sarzak_single/types/subtype.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"subtype-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"subtype-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::isa::Isa; @@ -29,30 +27,26 @@ pub struct Subtype { impl Subtype { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"subtype-struct-impl-new"}}} /// Inter a new 'Subtype' in the store, and return it's `id`. - pub fn new( - isa: &Rc>, - obj_id: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { + pub fn new(isa: &Isa, obj_id: &Object, store: &mut SarzakSingleStore) -> Subtype { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Subtype { + let new = Subtype { id, - isa: isa.borrow().id, - obj_id: obj_id.borrow().id, - })); + isa: isa.id, + obj_id: obj_id.id, + }; store.inter_subtype(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"subtype-struct-impl-nav-forward-to-isa"}}} /// Navigate to [`Isa`] across R27(1-*) - pub fn r27_isa<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r27_isa<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Isa> { vec![store.exhume_isa(&self.isa).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"subtype-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R15(1-*) - pub fn r15_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r15_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/supertype.rs b/src/v2/sarzak_single/types/supertype.rs index 05df13cc..dac3da04 100644 --- a/src/v2/sarzak_single/types/supertype.rs +++ b/src/v2/sarzak_single/types/supertype.rs @@ -1,7 +1,5 @@ // {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"supertype-struct-definition-file"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"supertype-use-statements"}}} -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; use crate::v2::sarzak_single::types::isa::Isa; @@ -28,31 +26,28 @@ pub struct Supertype { impl Supertype { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"supertype-struct-impl-new"}}} /// Inter a new 'Supertype' in the store, and return it's `id`. - pub fn new( - obj_id: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { + pub fn new(obj_id: &Object, store: &mut SarzakSingleStore) -> Supertype { let id = Uuid::new_v4(); - let new = Rc::new(RefCell::new(Supertype { + let new = Supertype { id, - obj_id: obj_id.borrow().id, - })); + obj_id: obj_id.id, + }; store.inter_supertype(new.clone()); new } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"supertype-struct-impl-nav-forward-to-obj_id"}}} /// Navigate to [`Object`] across R14(1-*) - pub fn r14_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r14_object<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Object> { vec![store.exhume_object(&self.obj_id).unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"supertype-struct-impl-nav-backward-one-to-isa"}}} /// Navigate to [`Isa`] across R13(1-1) - pub fn r13_isa<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r13_isa<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Isa> { vec![store .iter_isa() - .find(|isa| isa.borrow().supertype == self.id) + .find(|isa| isa.supertype == self.id) .unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/sarzak_single/types/ty.rs b/src/v2/sarzak_single/types/ty.rs index 54613352..c8b21e62 100644 --- a/src/v2/sarzak_single/types/ty.rs +++ b/src/v2/sarzak_single/types/ty.rs @@ -10,8 +10,6 @@ use crate::v2::sarzak_single::types::object::Object; use crate::v2::sarzak_single::types::s_string::S_STRING; use crate::v2::sarzak_single::types::s_uuid::S_UUID; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::rc::Rc; use uuid::Uuid; // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -38,63 +36,47 @@ pub enum Ty { impl Ty { // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ty-new-impl"}}} /// Create a new instance of Ty::Boolean - pub fn new_boolean(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_ty(&BOOLEAN).unwrap() + pub fn new_boolean() -> Self { + // This is already in the store, see associated function `new` above. + Self::Boolean(BOOLEAN) } /// Create a new instance of Ty::External - pub fn new_external( - external: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { - let id = external.borrow().id; - if let Some(external) = store.exhume_ty(&id) { - external - } else { - let new = Rc::new(RefCell::new(Self::External(id))); - store.inter_ty(new.clone()); - new - } + pub fn new_external(external: &External, store: &mut SarzakSingleStore) -> Self { + let new = Self::External(external.id); + store.inter_ty(new.clone()); + new } // wtf? /// Create a new instance of Ty::Float - pub fn new_float(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_ty(&FLOAT).unwrap() + pub fn new_float() -> Self { + // This is already in the store, see associated function `new` above. + Self::Float(FLOAT) } /// Create a new instance of Ty::Integer - pub fn new_integer(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_ty(&INTEGER).unwrap() + pub fn new_integer() -> Self { + // This is already in the store, see associated function `new` above. + Self::Integer(INTEGER) } /// Create a new instance of Ty::Object - pub fn new_object( - object: &Rc>, - store: &mut SarzakSingleStore, - ) -> Rc> { - let id = object.borrow().id; - if let Some(object) = store.exhume_ty(&id) { - object - } else { - let new = Rc::new(RefCell::new(Self::Object(id))); - store.inter_ty(new.clone()); - new - } + pub fn new_object(object: &Object, store: &mut SarzakSingleStore) -> Self { + let new = Self::Object(object.id); + store.inter_ty(new.clone()); + new } // wtf? /// Create a new instance of Ty::SString - pub fn new_s_string(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_ty(&S_STRING).unwrap() + pub fn new_s_string() -> Self { + // This is already in the store, see associated function `new` above. + Self::SString(S_STRING) } /// Create a new instance of Ty::SUuid - pub fn new_s_uuid(store: &SarzakSingleStore) -> Rc> { - // This is already in the store. - store.exhume_ty(&S_UUID).unwrap() + pub fn new_s_uuid() -> Self { + // This is already in the store, see associated function `new` above. + Self::SUuid(S_UUID) } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} @@ -113,10 +95,10 @@ impl Ty { // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ty-struct-impl-nav-backward-one-to-attribute"}}} /// Navigate to [`Attribute`] across R2(1-1) - pub fn r2_attribute<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec>> { + pub fn r2_attribute<'a>(&'a self, store: &'a SarzakSingleStore) -> Vec<&Attribute> { vec![store .iter_attribute() - .find(|attribute| attribute.borrow().ty == self.id()) + .find(|attribute| attribute.ty == self.id()) .unwrap()] } // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/woog_single.rs b/src/v2/woog_single.rs new file mode 100644 index 00000000..3cb6c554 --- /dev/null +++ b/src/v2/woog_single.rs @@ -0,0 +1,13 @@ +//! Woog Domain +//! +//! This file was generated by: `sarzak new "woog"`. +use uuid::{uuid, Uuid}; + +pub mod store; +pub mod types; + +pub use store::ObjectStore; +pub use types::*; + +// woog +pub const UUID_NS: Uuid = uuid!("288d4258-fdbd-52dd-a38b-976fd132d096"); diff --git a/src/v2/woog_single/store.rs b/src/v2/woog_single/store.rs new file mode 100644 index 00000000..66a90ea0 --- /dev/null +++ b/src/v2/woog_single/store.rs @@ -0,0 +1,2474 @@ +//! v2::woog_single Object Store +//! +//! The ObjectStore contains instances of objects in the domain. +//! The instances are stored in a hash map, keyed by the object's UUID. +//! This is used during code generation, and probably not useful elsewhere. +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::woog_single-object-store-file"}}} +//! +//! # Contents: +//! +//! * [`Access`] +//! * [`Block`] +//! * [`Call`] +//! * [`Constant`] +//! * [`Enumeration`] +//! * [`EnumerationField`] +//! * [`Expression`] +//! * [`Field`] +//! * [`Function`] +//! * [`GenerationUnit`] +//! * [`GraceType`] +//! * [`Item`] +//! * [`XLet`] +//! * [`Local`] +//! * [`ObjectMethod`] +//! * [`WoogOption`] +//! * [`Ownership`] +//! * [`Parameter`] +//! * [`Reference`] +//! * [`Statement`] +//! * [`Structure`] +//! * [`StructureField`] +//! * [`SymbolTable`] +//! * [`TimeStamp`] +//! * [`XValue`] +//! * [`Variable`] +//! * [`Visibility`] +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::woog_single-object-store-definition"}}} +use std::{ + fs, + io::{self, prelude::*}, + path::Path, + time::SystemTime, +}; + +use heck::ToUpperCamelCase; +use rustc_hash::FxHashMap as HashMap; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use crate::v2::woog_single::types::{ + Access, Block, Call, Constant, Enumeration, EnumerationField, Expression, Field, Function, + GenerationUnit, GraceType, Item, Local, ObjectMethod, Ownership, Parameter, Reference, + Statement, Structure, StructureField, SymbolTable, TimeStamp, Variable, Visibility, WoogOption, + XLet, XValue, BORROWED, IMPLEMENTATION, KRATE, LITERAL, MUTABLE, OWNED, PRIVATE, PUBLIC, USIZE, +}; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ObjectStore { + access: HashMap, + block: HashMap, + call: HashMap, + constant: HashMap, + enumeration: HashMap, + enumeration_field: HashMap, + expression: HashMap, + field: HashMap, + field_id_by_name: HashMap, + function: HashMap, + function_id_by_name: HashMap, + generation_unit: HashMap, + grace_type: HashMap, + item: HashMap, + x_let: HashMap, + local: HashMap, + object_method: HashMap, + woog_option: HashMap, + ownership: HashMap, + parameter: HashMap, + reference: HashMap, + statement: HashMap, + structure: HashMap, + structure_field: HashMap, + symbol_table: HashMap, + time_stamp: HashMap, + x_value: HashMap, + variable: HashMap, + visibility: HashMap, +} + +impl ObjectStore { + pub fn new() -> Self { + let mut store = Self { + access: HashMap::default(), + block: HashMap::default(), + call: HashMap::default(), + constant: HashMap::default(), + enumeration: HashMap::default(), + enumeration_field: HashMap::default(), + expression: HashMap::default(), + field: HashMap::default(), + field_id_by_name: HashMap::default(), + function: HashMap::default(), + function_id_by_name: HashMap::default(), + generation_unit: HashMap::default(), + grace_type: HashMap::default(), + item: HashMap::default(), + x_let: HashMap::default(), + local: HashMap::default(), + object_method: HashMap::default(), + woog_option: HashMap::default(), + ownership: HashMap::default(), + parameter: HashMap::default(), + reference: HashMap::default(), + statement: HashMap::default(), + structure: HashMap::default(), + structure_field: HashMap::default(), + symbol_table: HashMap::default(), + time_stamp: HashMap::default(), + x_value: HashMap::default(), + variable: HashMap::default(), + visibility: HashMap::default(), + }; + + // Initialize Singleton Subtypes + // 💥 Look at how beautiful this generated code is for super/sub-type graphs! + // I remember having a bit of a struggle making it work. It's recursive, with + // a lot of special cases, and I think it calls other recursive functions...💥 + store.inter_expression(Expression::Literal(LITERAL)); + store.inter_grace_type(GraceType::Usize(USIZE)); + store.inter_item(Item::Implementation(IMPLEMENTATION)); + store.inter_ownership(Ownership::Borrowed(BORROWED)); + store.inter_ownership(Ownership::Mutable(MUTABLE)); + store.inter_ownership(Ownership::Owned(OWNED)); + store.inter_visibility(Visibility::Krate(KRATE)); + store.inter_visibility(Visibility::Private(PRIVATE)); + store.inter_visibility(Visibility::Public(PUBLIC)); + + store + } + + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::woog_single-object-store-methods"}}} + /// Inter (insert) [`Access`] into the store. + /// + pub fn inter_access(&mut self, access: Access) { + self.access.insert(access.id, (access, SystemTime::now())); + } + + /// Exhume (get) [`Access`] from the store. + /// + pub fn exhume_access(&self, id: &Uuid) -> Option<&Access> { + self.access.get(id).map(|access| &access.0) + } + + /// Exorcise (remove) [`Access`] from the store. + /// + pub fn exorcise_access(&mut self, id: &Uuid) -> Option { + self.access.remove(id).map(|access| access.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Access>`. + /// + pub fn iter_access(&self) -> impl Iterator { + self.access.values().map(|access| &access.0) + } + + /// Get the timestamp for Access. + /// + pub fn access_timestamp(&self, access: &Access) -> SystemTime { + self.access + .get(&access.id) + .map(|access| access.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Block`] into the store. + /// + pub fn inter_block(&mut self, block: Block) { + self.block.insert(block.id, (block, SystemTime::now())); + } + + /// Exhume (get) [`Block`] from the store. + /// + pub fn exhume_block(&self, id: &Uuid) -> Option<&Block> { + self.block.get(id).map(|block| &block.0) + } + + /// Exorcise (remove) [`Block`] from the store. + /// + pub fn exorcise_block(&mut self, id: &Uuid) -> Option { + self.block.remove(id).map(|block| block.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Block>`. + /// + pub fn iter_block(&self) -> impl Iterator { + self.block.values().map(|block| &block.0) + } + + /// Get the timestamp for Block. + /// + pub fn block_timestamp(&self, block: &Block) -> SystemTime { + self.block + .get(&block.id) + .map(|block| block.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Call`] into the store. + /// + pub fn inter_call(&mut self, call: Call) { + self.call.insert(call.id, (call, SystemTime::now())); + } + + /// Exhume (get) [`Call`] from the store. + /// + pub fn exhume_call(&self, id: &Uuid) -> Option<&Call> { + self.call.get(id).map(|call| &call.0) + } + + /// Exorcise (remove) [`Call`] from the store. + /// + pub fn exorcise_call(&mut self, id: &Uuid) -> Option { + self.call.remove(id).map(|call| call.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Call>`. + /// + pub fn iter_call(&self) -> impl Iterator { + self.call.values().map(|call| &call.0) + } + + /// Get the timestamp for Call. + /// + pub fn call_timestamp(&self, call: &Call) -> SystemTime { + self.call + .get(&call.id) + .map(|call| call.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Constant`] into the store. + /// + pub fn inter_constant(&mut self, constant: Constant) { + self.constant + .insert(constant.id, (constant, SystemTime::now())); + } + + /// Exhume (get) [`Constant`] from the store. + /// + pub fn exhume_constant(&self, id: &Uuid) -> Option<&Constant> { + self.constant.get(id).map(|constant| &constant.0) + } + + /// Exorcise (remove) [`Constant`] from the store. + /// + pub fn exorcise_constant(&mut self, id: &Uuid) -> Option { + self.constant.remove(id).map(|constant| constant.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Constant>`. + /// + pub fn iter_constant(&self) -> impl Iterator { + self.constant.values().map(|constant| &constant.0) + } + + /// Get the timestamp for Constant. + /// + pub fn constant_timestamp(&self, constant: &Constant) -> SystemTime { + self.constant + .get(&constant.id) + .map(|constant| constant.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Enumeration`] into the store. + /// + pub fn inter_enumeration(&mut self, enumeration: Enumeration) { + self.enumeration + .insert(enumeration.id, (enumeration, SystemTime::now())); + } + + /// Exhume (get) [`Enumeration`] from the store. + /// + pub fn exhume_enumeration(&self, id: &Uuid) -> Option<&Enumeration> { + self.enumeration.get(id).map(|enumeration| &enumeration.0) + } + + /// Exorcise (remove) [`Enumeration`] from the store. + /// + pub fn exorcise_enumeration(&mut self, id: &Uuid) -> Option { + self.enumeration.remove(id).map(|enumeration| enumeration.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Enumeration>`. + /// + pub fn iter_enumeration(&self) -> impl Iterator { + self.enumeration.values().map(|enumeration| &enumeration.0) + } + + /// Get the timestamp for Enumeration. + /// + pub fn enumeration_timestamp(&self, enumeration: &Enumeration) -> SystemTime { + self.enumeration + .get(&enumeration.id) + .map(|enumeration| enumeration.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`EnumerationField`] into the store. + /// + pub fn inter_enumeration_field(&mut self, enumeration_field: EnumerationField) { + self.enumeration_field + .insert(enumeration_field.id, (enumeration_field, SystemTime::now())); + } + + /// Exhume (get) [`EnumerationField`] from the store. + /// + pub fn exhume_enumeration_field(&self, id: &Uuid) -> Option<&EnumerationField> { + self.enumeration_field + .get(id) + .map(|enumeration_field| &enumeration_field.0) + } + + /// Exorcise (remove) [`EnumerationField`] from the store. + /// + pub fn exorcise_enumeration_field(&mut self, id: &Uuid) -> Option { + self.enumeration_field + .remove(id) + .map(|enumeration_field| enumeration_field.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, EnumerationField>`. + /// + pub fn iter_enumeration_field(&self) -> impl Iterator { + self.enumeration_field + .values() + .map(|enumeration_field| &enumeration_field.0) + } + + /// Get the timestamp for EnumerationField. + /// + pub fn enumeration_field_timestamp(&self, enumeration_field: &EnumerationField) -> SystemTime { + self.enumeration_field + .get(&enumeration_field.id) + .map(|enumeration_field| enumeration_field.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Expression`] into the store. + /// + pub fn inter_expression(&mut self, expression: Expression) { + self.expression + .insert(expression.id(), (expression, SystemTime::now())); + } + + /// Exhume (get) [`Expression`] from the store. + /// + pub fn exhume_expression(&self, id: &Uuid) -> Option<&Expression> { + self.expression.get(id).map(|expression| &expression.0) + } + + /// Exorcise (remove) [`Expression`] from the store. + /// + pub fn exorcise_expression(&mut self, id: &Uuid) -> Option { + self.expression.remove(id).map(|expression| expression.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Expression>`. + /// + pub fn iter_expression(&self) -> impl Iterator { + self.expression.values().map(|expression| &expression.0) + } + + /// Get the timestamp for Expression. + /// + pub fn expression_timestamp(&self, expression: &Expression) -> SystemTime { + self.expression + .get(&expression.id()) + .map(|expression| expression.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Field`] into the store. + /// + pub fn inter_field(&mut self, field: Field) { + let value = (field, SystemTime::now()); + self.field_id_by_name + .insert(value.0.name.to_upper_camel_case(), (value.0.id, value.1)); + self.field.insert(value.0.id, value); + } + + /// Exhume (get) [`Field`] from the store. + /// + pub fn exhume_field(&self, id: &Uuid) -> Option<&Field> { + self.field.get(id).map(|field| &field.0) + } + + /// Exorcise (remove) [`Field`] from the store. + /// + pub fn exorcise_field(&mut self, id: &Uuid) -> Option { + self.field.remove(id).map(|field| field.0) + } + + /// Exhume [`Field`] id from the store by name. + /// + pub fn exhume_field_id_by_name(&self, name: &str) -> Option { + self.field_id_by_name.get(name).map(|field| field.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Field>`. + /// + pub fn iter_field(&self) -> impl Iterator { + self.field.values().map(|field| &field.0) + } + + /// Get the timestamp for Field. + /// + pub fn field_timestamp(&self, field: &Field) -> SystemTime { + self.field + .get(&field.id) + .map(|field| field.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Function`] into the store. + /// + pub fn inter_function(&mut self, function: Function) { + let value = (function, SystemTime::now()); + self.function_id_by_name + .insert(value.0.name.to_upper_camel_case(), (value.0.id, value.1)); + self.function.insert(value.0.id, value); + } + + /// Exhume (get) [`Function`] from the store. + /// + pub fn exhume_function(&self, id: &Uuid) -> Option<&Function> { + self.function.get(id).map(|function| &function.0) + } + + /// Exorcise (remove) [`Function`] from the store. + /// + pub fn exorcise_function(&mut self, id: &Uuid) -> Option { + self.function.remove(id).map(|function| function.0) + } + + /// Exhume [`Function`] id from the store by name. + /// + pub fn exhume_function_id_by_name(&self, name: &str) -> Option { + self.function_id_by_name + .get(name) + .map(|function| function.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Function>`. + /// + pub fn iter_function(&self) -> impl Iterator { + self.function.values().map(|function| &function.0) + } + + /// Get the timestamp for Function. + /// + pub fn function_timestamp(&self, function: &Function) -> SystemTime { + self.function + .get(&function.id) + .map(|function| function.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`GenerationUnit`] into the store. + /// + pub fn inter_generation_unit(&mut self, generation_unit: GenerationUnit) { + self.generation_unit + .insert(generation_unit.id, (generation_unit, SystemTime::now())); + } + + /// Exhume (get) [`GenerationUnit`] from the store. + /// + pub fn exhume_generation_unit(&self, id: &Uuid) -> Option<&GenerationUnit> { + self.generation_unit + .get(id) + .map(|generation_unit| &generation_unit.0) + } + + /// Exorcise (remove) [`GenerationUnit`] from the store. + /// + pub fn exorcise_generation_unit(&mut self, id: &Uuid) -> Option { + self.generation_unit + .remove(id) + .map(|generation_unit| generation_unit.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, GenerationUnit>`. + /// + pub fn iter_generation_unit(&self) -> impl Iterator { + self.generation_unit + .values() + .map(|generation_unit| &generation_unit.0) + } + + /// Get the timestamp for GenerationUnit. + /// + pub fn generation_unit_timestamp(&self, generation_unit: &GenerationUnit) -> SystemTime { + self.generation_unit + .get(&generation_unit.id) + .map(|generation_unit| generation_unit.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`GraceType`] into the store. + /// + pub fn inter_grace_type(&mut self, grace_type: GraceType) { + self.grace_type + .insert(grace_type.id(), (grace_type, SystemTime::now())); + } + + /// Exhume (get) [`GraceType`] from the store. + /// + pub fn exhume_grace_type(&self, id: &Uuid) -> Option<&GraceType> { + self.grace_type.get(id).map(|grace_type| &grace_type.0) + } + + /// Exorcise (remove) [`GraceType`] from the store. + /// + pub fn exorcise_grace_type(&mut self, id: &Uuid) -> Option { + self.grace_type.remove(id).map(|grace_type| grace_type.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, GraceType>`. + /// + pub fn iter_grace_type(&self) -> impl Iterator { + self.grace_type.values().map(|grace_type| &grace_type.0) + } + + /// Get the timestamp for GraceType. + /// + pub fn grace_type_timestamp(&self, grace_type: &GraceType) -> SystemTime { + self.grace_type + .get(&grace_type.id()) + .map(|grace_type| grace_type.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Item`] into the store. + /// + pub fn inter_item(&mut self, item: Item) { + self.item.insert(item.id(), (item, SystemTime::now())); + } + + /// Exhume (get) [`Item`] from the store. + /// + pub fn exhume_item(&self, id: &Uuid) -> Option<&Item> { + self.item.get(id).map(|item| &item.0) + } + + /// Exorcise (remove) [`Item`] from the store. + /// + pub fn exorcise_item(&mut self, id: &Uuid) -> Option { + self.item.remove(id).map(|item| item.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Item>`. + /// + pub fn iter_item(&self) -> impl Iterator { + self.item.values().map(|item| &item.0) + } + + /// Get the timestamp for Item. + /// + pub fn item_timestamp(&self, item: &Item) -> SystemTime { + self.item + .get(&item.id()) + .map(|item| item.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`XLet`] into the store. + /// + pub fn inter_x_let(&mut self, x_let: XLet) { + self.x_let.insert(x_let.id, (x_let, SystemTime::now())); + } + + /// Exhume (get) [`XLet`] from the store. + /// + pub fn exhume_x_let(&self, id: &Uuid) -> Option<&XLet> { + self.x_let.get(id).map(|x_let| &x_let.0) + } + + /// Exorcise (remove) [`XLet`] from the store. + /// + pub fn exorcise_x_let(&mut self, id: &Uuid) -> Option { + self.x_let.remove(id).map(|x_let| x_let.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, XLet>`. + /// + pub fn iter_x_let(&self) -> impl Iterator { + self.x_let.values().map(|x_let| &x_let.0) + } + + /// Get the timestamp for XLet. + /// + pub fn x_let_timestamp(&self, x_let: &XLet) -> SystemTime { + self.x_let + .get(&x_let.id) + .map(|x_let| x_let.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Local`] into the store. + /// + pub fn inter_local(&mut self, local: Local) { + self.local.insert(local.id, (local, SystemTime::now())); + } + + /// Exhume (get) [`Local`] from the store. + /// + pub fn exhume_local(&self, id: &Uuid) -> Option<&Local> { + self.local.get(id).map(|local| &local.0) + } + + /// Exorcise (remove) [`Local`] from the store. + /// + pub fn exorcise_local(&mut self, id: &Uuid) -> Option { + self.local.remove(id).map(|local| local.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Local>`. + /// + pub fn iter_local(&self) -> impl Iterator { + self.local.values().map(|local| &local.0) + } + + /// Get the timestamp for Local. + /// + pub fn local_timestamp(&self, local: &Local) -> SystemTime { + self.local + .get(&local.id) + .map(|local| local.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`ObjectMethod`] into the store. + /// + pub fn inter_object_method(&mut self, object_method: ObjectMethod) { + self.object_method + .insert(object_method.id, (object_method, SystemTime::now())); + } + + /// Exhume (get) [`ObjectMethod`] from the store. + /// + pub fn exhume_object_method(&self, id: &Uuid) -> Option<&ObjectMethod> { + self.object_method + .get(id) + .map(|object_method| &object_method.0) + } + + /// Exorcise (remove) [`ObjectMethod`] from the store. + /// + pub fn exorcise_object_method(&mut self, id: &Uuid) -> Option { + self.object_method + .remove(id) + .map(|object_method| object_method.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, ObjectMethod>`. + /// + pub fn iter_object_method(&self) -> impl Iterator { + self.object_method + .values() + .map(|object_method| &object_method.0) + } + + /// Get the timestamp for ObjectMethod. + /// + pub fn object_method_timestamp(&self, object_method: &ObjectMethod) -> SystemTime { + self.object_method + .get(&object_method.id) + .map(|object_method| object_method.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`WoogOption`] into the store. + /// + pub fn inter_woog_option(&mut self, woog_option: WoogOption) { + self.woog_option + .insert(woog_option.id, (woog_option, SystemTime::now())); + } + + /// Exhume (get) [`WoogOption`] from the store. + /// + pub fn exhume_woog_option(&self, id: &Uuid) -> Option<&WoogOption> { + self.woog_option.get(id).map(|woog_option| &woog_option.0) + } + + /// Exorcise (remove) [`WoogOption`] from the store. + /// + pub fn exorcise_woog_option(&mut self, id: &Uuid) -> Option { + self.woog_option.remove(id).map(|woog_option| woog_option.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, WoogOption>`. + /// + pub fn iter_woog_option(&self) -> impl Iterator { + self.woog_option.values().map(|woog_option| &woog_option.0) + } + + /// Get the timestamp for WoogOption. + /// + pub fn woog_option_timestamp(&self, woog_option: &WoogOption) -> SystemTime { + self.woog_option + .get(&woog_option.id) + .map(|woog_option| woog_option.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Ownership`] into the store. + /// + pub fn inter_ownership(&mut self, ownership: Ownership) { + self.ownership + .insert(ownership.id(), (ownership, SystemTime::now())); + } + + /// Exhume (get) [`Ownership`] from the store. + /// + pub fn exhume_ownership(&self, id: &Uuid) -> Option<&Ownership> { + self.ownership.get(id).map(|ownership| &ownership.0) + } + + /// Exorcise (remove) [`Ownership`] from the store. + /// + pub fn exorcise_ownership(&mut self, id: &Uuid) -> Option { + self.ownership.remove(id).map(|ownership| ownership.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Ownership>`. + /// + pub fn iter_ownership(&self) -> impl Iterator { + self.ownership.values().map(|ownership| &ownership.0) + } + + /// Get the timestamp for Ownership. + /// + pub fn ownership_timestamp(&self, ownership: &Ownership) -> SystemTime { + self.ownership + .get(&ownership.id()) + .map(|ownership| ownership.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Parameter`] into the store. + /// + pub fn inter_parameter(&mut self, parameter: Parameter) { + self.parameter + .insert(parameter.id, (parameter, SystemTime::now())); + } + + /// Exhume (get) [`Parameter`] from the store. + /// + pub fn exhume_parameter(&self, id: &Uuid) -> Option<&Parameter> { + self.parameter.get(id).map(|parameter| ¶meter.0) + } + + /// Exorcise (remove) [`Parameter`] from the store. + /// + pub fn exorcise_parameter(&mut self, id: &Uuid) -> Option { + self.parameter.remove(id).map(|parameter| parameter.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Parameter>`. + /// + pub fn iter_parameter(&self) -> impl Iterator { + self.parameter.values().map(|parameter| ¶meter.0) + } + + /// Get the timestamp for Parameter. + /// + pub fn parameter_timestamp(&self, parameter: &Parameter) -> SystemTime { + self.parameter + .get(¶meter.id) + .map(|parameter| parameter.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Reference`] into the store. + /// + pub fn inter_reference(&mut self, reference: Reference) { + self.reference + .insert(reference.id, (reference, SystemTime::now())); + } + + /// Exhume (get) [`Reference`] from the store. + /// + pub fn exhume_reference(&self, id: &Uuid) -> Option<&Reference> { + self.reference.get(id).map(|reference| &reference.0) + } + + /// Exorcise (remove) [`Reference`] from the store. + /// + pub fn exorcise_reference(&mut self, id: &Uuid) -> Option { + self.reference.remove(id).map(|reference| reference.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Reference>`. + /// + pub fn iter_reference(&self) -> impl Iterator { + self.reference.values().map(|reference| &reference.0) + } + + /// Get the timestamp for Reference. + /// + pub fn reference_timestamp(&self, reference: &Reference) -> SystemTime { + self.reference + .get(&reference.id) + .map(|reference| reference.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Statement`] into the store. + /// + pub fn inter_statement(&mut self, statement: Statement) { + self.statement + .insert(statement.id, (statement, SystemTime::now())); + } + + /// Exhume (get) [`Statement`] from the store. + /// + pub fn exhume_statement(&self, id: &Uuid) -> Option<&Statement> { + self.statement.get(id).map(|statement| &statement.0) + } + + /// Exorcise (remove) [`Statement`] from the store. + /// + pub fn exorcise_statement(&mut self, id: &Uuid) -> Option { + self.statement.remove(id).map(|statement| statement.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Statement>`. + /// + pub fn iter_statement(&self) -> impl Iterator { + self.statement.values().map(|statement| &statement.0) + } + + /// Get the timestamp for Statement. + /// + pub fn statement_timestamp(&self, statement: &Statement) -> SystemTime { + self.statement + .get(&statement.id) + .map(|statement| statement.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Structure`] into the store. + /// + pub fn inter_structure(&mut self, structure: Structure) { + self.structure + .insert(structure.id, (structure, SystemTime::now())); + } + + /// Exhume (get) [`Structure`] from the store. + /// + pub fn exhume_structure(&self, id: &Uuid) -> Option<&Structure> { + self.structure.get(id).map(|structure| &structure.0) + } + + /// Exorcise (remove) [`Structure`] from the store. + /// + pub fn exorcise_structure(&mut self, id: &Uuid) -> Option { + self.structure.remove(id).map(|structure| structure.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Structure>`. + /// + pub fn iter_structure(&self) -> impl Iterator { + self.structure.values().map(|structure| &structure.0) + } + + /// Get the timestamp for Structure. + /// + pub fn structure_timestamp(&self, structure: &Structure) -> SystemTime { + self.structure + .get(&structure.id) + .map(|structure| structure.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`StructureField`] into the store. + /// + pub fn inter_structure_field(&mut self, structure_field: StructureField) { + self.structure_field + .insert(structure_field.id, (structure_field, SystemTime::now())); + } + + /// Exhume (get) [`StructureField`] from the store. + /// + pub fn exhume_structure_field(&self, id: &Uuid) -> Option<&StructureField> { + self.structure_field + .get(id) + .map(|structure_field| &structure_field.0) + } + + /// Exorcise (remove) [`StructureField`] from the store. + /// + pub fn exorcise_structure_field(&mut self, id: &Uuid) -> Option { + self.structure_field + .remove(id) + .map(|structure_field| structure_field.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, StructureField>`. + /// + pub fn iter_structure_field(&self) -> impl Iterator { + self.structure_field + .values() + .map(|structure_field| &structure_field.0) + } + + /// Get the timestamp for StructureField. + /// + pub fn structure_field_timestamp(&self, structure_field: &StructureField) -> SystemTime { + self.structure_field + .get(&structure_field.id) + .map(|structure_field| structure_field.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`SymbolTable`] into the store. + /// + pub fn inter_symbol_table(&mut self, symbol_table: SymbolTable) { + self.symbol_table + .insert(symbol_table.id, (symbol_table, SystemTime::now())); + } + + /// Exhume (get) [`SymbolTable`] from the store. + /// + pub fn exhume_symbol_table(&self, id: &Uuid) -> Option<&SymbolTable> { + self.symbol_table + .get(id) + .map(|symbol_table| &symbol_table.0) + } + + /// Exorcise (remove) [`SymbolTable`] from the store. + /// + pub fn exorcise_symbol_table(&mut self, id: &Uuid) -> Option { + self.symbol_table + .remove(id) + .map(|symbol_table| symbol_table.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, SymbolTable>`. + /// + pub fn iter_symbol_table(&self) -> impl Iterator { + self.symbol_table + .values() + .map(|symbol_table| &symbol_table.0) + } + + /// Get the timestamp for SymbolTable. + /// + pub fn symbol_table_timestamp(&self, symbol_table: &SymbolTable) -> SystemTime { + self.symbol_table + .get(&symbol_table.id) + .map(|symbol_table| symbol_table.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`TimeStamp`] into the store. + /// + pub fn inter_time_stamp(&mut self, time_stamp: TimeStamp) { + self.time_stamp + .insert(time_stamp.id, (time_stamp, SystemTime::now())); + } + + /// Exhume (get) [`TimeStamp`] from the store. + /// + pub fn exhume_time_stamp(&self, id: &Uuid) -> Option<&TimeStamp> { + self.time_stamp.get(id).map(|time_stamp| &time_stamp.0) + } + + /// Exorcise (remove) [`TimeStamp`] from the store. + /// + pub fn exorcise_time_stamp(&mut self, id: &Uuid) -> Option { + self.time_stamp.remove(id).map(|time_stamp| time_stamp.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, TimeStamp>`. + /// + pub fn iter_time_stamp(&self) -> impl Iterator { + self.time_stamp.values().map(|time_stamp| &time_stamp.0) + } + + /// Get the timestamp for TimeStamp. + /// + pub fn time_stamp_timestamp(&self, time_stamp: &TimeStamp) -> SystemTime { + self.time_stamp + .get(&time_stamp.id) + .map(|time_stamp| time_stamp.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`XValue`] into the store. + /// + pub fn inter_x_value(&mut self, x_value: XValue) { + self.x_value + .insert(x_value.id, (x_value, SystemTime::now())); + } + + /// Exhume (get) [`XValue`] from the store. + /// + pub fn exhume_x_value(&self, id: &Uuid) -> Option<&XValue> { + self.x_value.get(id).map(|x_value| &x_value.0) + } + + /// Exorcise (remove) [`XValue`] from the store. + /// + pub fn exorcise_x_value(&mut self, id: &Uuid) -> Option { + self.x_value.remove(id).map(|x_value| x_value.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, XValue>`. + /// + pub fn iter_x_value(&self) -> impl Iterator { + self.x_value.values().map(|x_value| &x_value.0) + } + + /// Get the timestamp for XValue. + /// + pub fn x_value_timestamp(&self, x_value: &XValue) -> SystemTime { + self.x_value + .get(&x_value.id) + .map(|x_value| x_value.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Variable`] into the store. + /// + pub fn inter_variable(&mut self, variable: Variable) { + self.variable + .insert(variable.id, (variable, SystemTime::now())); + } + + /// Exhume (get) [`Variable`] from the store. + /// + pub fn exhume_variable(&self, id: &Uuid) -> Option<&Variable> { + self.variable.get(id).map(|variable| &variable.0) + } + + /// Exorcise (remove) [`Variable`] from the store. + /// + pub fn exorcise_variable(&mut self, id: &Uuid) -> Option { + self.variable.remove(id).map(|variable| variable.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Variable>`. + /// + pub fn iter_variable(&self) -> impl Iterator { + self.variable.values().map(|variable| &variable.0) + } + + /// Get the timestamp for Variable. + /// + pub fn variable_timestamp(&self, variable: &Variable) -> SystemTime { + self.variable + .get(&variable.id) + .map(|variable| variable.1) + .unwrap_or(SystemTime::now()) + } + + /// Inter (insert) [`Visibility`] into the store. + /// + pub fn inter_visibility(&mut self, visibility: Visibility) { + self.visibility + .insert(visibility.id(), (visibility, SystemTime::now())); + } + + /// Exhume (get) [`Visibility`] from the store. + /// + pub fn exhume_visibility(&self, id: &Uuid) -> Option<&Visibility> { + self.visibility.get(id).map(|visibility| &visibility.0) + } + + /// Exorcise (remove) [`Visibility`] from the store. + /// + pub fn exorcise_visibility(&mut self, id: &Uuid) -> Option { + self.visibility.remove(id).map(|visibility| visibility.0) + } + + /// Get an iterator over the internal `HashMap<&Uuid, Visibility>`. + /// + pub fn iter_visibility(&self) -> impl Iterator { + self.visibility.values().map(|visibility| &visibility.0) + } + + /// Get the timestamp for Visibility. + /// + pub fn visibility_timestamp(&self, visibility: &Visibility) -> SystemTime { + self.visibility + .get(&visibility.id()) + .map(|visibility| visibility.1) + .unwrap_or(SystemTime::now()) + } + + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::woog_single-object-store-persistence"}}} + /// Persist the store. + /// + /// The store is persisted as a a bincode file. + pub fn persist_bincode>(&self, path: P) -> io::Result<()> { + let path = path.as_ref(); + let mut bin_file = fs::File::create(path)?; + let encoded: Vec = bincode::serialize(&self).unwrap(); + bin_file.write_all(&encoded)?; + Ok(()) + } + + /// Persist the store. + /// + /// The store is persisted as a directory of JSON files. The intention + /// is that this directory can be checked into version control. + /// In fact, I intend to add automagic git integration as an option. + pub fn persist>(&self, path: P) -> io::Result<()> { + let path = path.as_ref(); + fs::create_dir_all(path)?; + + let path = path.join("woog.json"); + fs::create_dir_all(&path)?; + + // Persist Access. + { + let path = path.join("access"); + fs::create_dir_all(&path)?; + for access_tuple in self.access.values() { + let path = path.join(format!("{}.json", access_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Access, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != access_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &access_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &access_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.access.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Block. + { + let path = path.join("block"); + fs::create_dir_all(&path)?; + for block_tuple in self.block.values() { + let path = path.join(format!("{}.json", block_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Block, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != block_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &block_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &block_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.block.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Call. + { + let path = path.join("call"); + fs::create_dir_all(&path)?; + for call_tuple in self.call.values() { + let path = path.join(format!("{}.json", call_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Call, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != call_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &call_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &call_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.call.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Constant. + { + let path = path.join("constant"); + fs::create_dir_all(&path)?; + for constant_tuple in self.constant.values() { + let path = path.join(format!("{}.json", constant_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Constant, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != constant_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &constant_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &constant_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.constant.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Enumeration. + { + let path = path.join("enumeration"); + fs::create_dir_all(&path)?; + for enumeration_tuple in self.enumeration.values() { + let path = path.join(format!("{}.json", enumeration_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Enumeration, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != enumeration_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &enumeration_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &enumeration_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.enumeration.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Enumeration Field. + { + let path = path.join("enumeration_field"); + fs::create_dir_all(&path)?; + for enumeration_field_tuple in self.enumeration_field.values() { + let path = path.join(format!("{}.json", enumeration_field_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (EnumerationField, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != enumeration_field_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &enumeration_field_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &enumeration_field_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.enumeration_field.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Expression. + { + let path = path.join("expression"); + fs::create_dir_all(&path)?; + for expression_tuple in self.expression.values() { + let path = path.join(format!("{}.json", expression_tuple.0.id())); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Expression, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != expression_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &expression_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &expression_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.expression.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Field. + { + let path = path.join("field"); + fs::create_dir_all(&path)?; + for field_tuple in self.field.values() { + let path = path.join(format!("{}.json", field_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Field, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != field_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &field_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &field_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.field.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Function. + { + let path = path.join("function"); + fs::create_dir_all(&path)?; + for function_tuple in self.function.values() { + let path = path.join(format!("{}.json", function_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Function, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != function_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &function_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &function_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.function.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Generation Unit. + { + let path = path.join("generation_unit"); + fs::create_dir_all(&path)?; + for generation_unit_tuple in self.generation_unit.values() { + let path = path.join(format!("{}.json", generation_unit_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (GenerationUnit, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != generation_unit_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &generation_unit_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &generation_unit_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.generation_unit.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Grace Type. + { + let path = path.join("grace_type"); + fs::create_dir_all(&path)?; + for grace_type_tuple in self.grace_type.values() { + let path = path.join(format!("{}.json", grace_type_tuple.0.id())); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (GraceType, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != grace_type_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &grace_type_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &grace_type_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.grace_type.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Item. + { + let path = path.join("item"); + fs::create_dir_all(&path)?; + for item_tuple in self.item.values() { + let path = path.join(format!("{}.json", item_tuple.0.id())); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Item, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != item_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &item_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &item_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.item.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Let. + { + let path = path.join("x_let"); + fs::create_dir_all(&path)?; + for x_let_tuple in self.x_let.values() { + let path = path.join(format!("{}.json", x_let_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (XLet, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != x_let_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &x_let_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &x_let_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.x_let.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Local. + { + let path = path.join("local"); + fs::create_dir_all(&path)?; + for local_tuple in self.local.values() { + let path = path.join(format!("{}.json", local_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Local, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != local_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &local_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &local_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.local.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Object Method. + { + let path = path.join("object_method"); + fs::create_dir_all(&path)?; + for object_method_tuple in self.object_method.values() { + let path = path.join(format!("{}.json", object_method_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (ObjectMethod, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != object_method_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &object_method_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &object_method_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.object_method.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Option. + { + let path = path.join("woog_option"); + fs::create_dir_all(&path)?; + for woog_option_tuple in self.woog_option.values() { + let path = path.join(format!("{}.json", woog_option_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (WoogOption, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != woog_option_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &woog_option_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &woog_option_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.woog_option.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Ownership. + { + let path = path.join("ownership"); + fs::create_dir_all(&path)?; + for ownership_tuple in self.ownership.values() { + let path = path.join(format!("{}.json", ownership_tuple.0.id())); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Ownership, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != ownership_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &ownership_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &ownership_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.ownership.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Parameter. + { + let path = path.join("parameter"); + fs::create_dir_all(&path)?; + for parameter_tuple in self.parameter.values() { + let path = path.join(format!("{}.json", parameter_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Parameter, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != parameter_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, ¶meter_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, ¶meter_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.parameter.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Reference. + { + let path = path.join("reference"); + fs::create_dir_all(&path)?; + for reference_tuple in self.reference.values() { + let path = path.join(format!("{}.json", reference_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Reference, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != reference_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &reference_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &reference_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.reference.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Statement. + { + let path = path.join("statement"); + fs::create_dir_all(&path)?; + for statement_tuple in self.statement.values() { + let path = path.join(format!("{}.json", statement_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Statement, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != statement_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &statement_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &statement_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.statement.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Structure. + { + let path = path.join("structure"); + fs::create_dir_all(&path)?; + for structure_tuple in self.structure.values() { + let path = path.join(format!("{}.json", structure_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Structure, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != structure_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &structure_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &structure_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.structure.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Structure Field. + { + let path = path.join("structure_field"); + fs::create_dir_all(&path)?; + for structure_field_tuple in self.structure_field.values() { + let path = path.join(format!("{}.json", structure_field_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (StructureField, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != structure_field_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &structure_field_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &structure_field_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.structure_field.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Symbol Table. + { + let path = path.join("symbol_table"); + fs::create_dir_all(&path)?; + for symbol_table_tuple in self.symbol_table.values() { + let path = path.join(format!("{}.json", symbol_table_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (SymbolTable, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != symbol_table_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &symbol_table_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &symbol_table_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.symbol_table.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Time Stamp. + { + let path = path.join("time_stamp"); + fs::create_dir_all(&path)?; + for time_stamp_tuple in self.time_stamp.values() { + let path = path.join(format!("{}.json", time_stamp_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (TimeStamp, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != time_stamp_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &time_stamp_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &time_stamp_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.time_stamp.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Value. + { + let path = path.join("x_value"); + fs::create_dir_all(&path)?; + for x_value_tuple in self.x_value.values() { + let path = path.join(format!("{}.json", x_value_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (XValue, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != x_value_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &x_value_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &x_value_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.x_value.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Variable. + { + let path = path.join("variable"); + fs::create_dir_all(&path)?; + for variable_tuple in self.variable.values() { + let path = path.join(format!("{}.json", variable_tuple.0.id)); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Variable, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != variable_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &variable_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &variable_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.variable.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + // Persist Visibility. + { + let path = path.join("visibility"); + fs::create_dir_all(&path)?; + for visibility_tuple in self.visibility.values() { + let path = path.join(format!("{}.json", visibility_tuple.0.id())); + if path.exists() { + let file = fs::File::open(&path)?; + let reader = io::BufReader::new(file); + let on_disk: (Visibility, SystemTime) = serde_json::from_reader(reader)?; + if on_disk.0 != visibility_tuple.0 { + let file = fs::File::create(path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &visibility_tuple)?; + } + } else { + let file = fs::File::create(&path)?; + let mut writer = io::BufWriter::new(file); + serde_json::to_writer_pretty(&mut writer, &visibility_tuple)?; + } + } + for file in fs::read_dir(&path)? { + let file = file?; + let path = file.path(); + let file_name = path.file_name().unwrap().to_str().unwrap(); + let id = file_name.split('.').next().unwrap(); + if let Ok(id) = Uuid::parse_str(id) { + if !self.visibility.contains_key(&id) { + fs::remove_file(path)?; + } + } + } + } + + Ok(()) + } + + /// Load the store. + /// + pub fn from_bincode(code: &[u8]) -> io::Result { + Ok(bincode::deserialize(code).unwrap()) + } + + /// The store is as a bincode file. + pub fn load_bincode>(path: P) -> io::Result { + let path = path.as_ref(); + let bin_file = fs::File::open(path)?; + Ok(bincode::deserialize_from(bin_file).unwrap()) + } + + /// Load the store. + /// + /// The store is persisted as a directory of JSON files. The intention + /// is that this directory can be checked into version control. + /// In fact, I intend to add automagic git integration as an option. + pub fn load>(path: P) -> io::Result { + let path = path.as_ref(); + let path = path.join("woog.json"); + + let mut store = Self::new(); + + // Load Access. + { + let path = path.join("access"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let access: (Access, SystemTime) = serde_json::from_reader(reader)?; + store.access.insert(access.0.id, access); + } + } + + // Load Block. + { + let path = path.join("block"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let block: (Block, SystemTime) = serde_json::from_reader(reader)?; + store.block.insert(block.0.id, block); + } + } + + // Load Call. + { + let path = path.join("call"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let call: (Call, SystemTime) = serde_json::from_reader(reader)?; + store.call.insert(call.0.id, call); + } + } + + // Load Constant. + { + let path = path.join("constant"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let constant: (Constant, SystemTime) = serde_json::from_reader(reader)?; + store.constant.insert(constant.0.id, constant); + } + } + + // Load Enumeration. + { + let path = path.join("enumeration"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let enumeration: (Enumeration, SystemTime) = serde_json::from_reader(reader)?; + store.enumeration.insert(enumeration.0.id, enumeration); + } + } + + // Load Enumeration Field. + { + let path = path.join("enumeration_field"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let enumeration_field: (EnumerationField, SystemTime) = + serde_json::from_reader(reader)?; + store + .enumeration_field + .insert(enumeration_field.0.id, enumeration_field); + } + } + + // Load Expression. + { + let path = path.join("expression"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let expression: (Expression, SystemTime) = serde_json::from_reader(reader)?; + store.expression.insert(expression.0.id(), expression); + } + } + + // Load Field. + { + let path = path.join("field"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let field: (Field, SystemTime) = serde_json::from_reader(reader)?; + store + .field_id_by_name + .insert(field.0.name.to_upper_camel_case(), (field.0.id, field.1)); + store.field.insert(field.0.id, field); + } + } + + // Load Function. + { + let path = path.join("function"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let function: (Function, SystemTime) = serde_json::from_reader(reader)?; + store.function_id_by_name.insert( + function.0.name.to_upper_camel_case(), + (function.0.id, function.1), + ); + store.function.insert(function.0.id, function); + } + } + + // Load Generation Unit. + { + let path = path.join("generation_unit"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let generation_unit: (GenerationUnit, SystemTime) = + serde_json::from_reader(reader)?; + store + .generation_unit + .insert(generation_unit.0.id, generation_unit); + } + } + + // Load Grace Type. + { + let path = path.join("grace_type"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let grace_type: (GraceType, SystemTime) = serde_json::from_reader(reader)?; + store.grace_type.insert(grace_type.0.id(), grace_type); + } + } + + // Load Item. + { + let path = path.join("item"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let item: (Item, SystemTime) = serde_json::from_reader(reader)?; + store.item.insert(item.0.id(), item); + } + } + + // Load Let. + { + let path = path.join("x_let"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let x_let: (XLet, SystemTime) = serde_json::from_reader(reader)?; + store.x_let.insert(x_let.0.id, x_let); + } + } + + // Load Local. + { + let path = path.join("local"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let local: (Local, SystemTime) = serde_json::from_reader(reader)?; + store.local.insert(local.0.id, local); + } + } + + // Load Object Method. + { + let path = path.join("object_method"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let object_method: (ObjectMethod, SystemTime) = serde_json::from_reader(reader)?; + store + .object_method + .insert(object_method.0.id, object_method); + } + } + + // Load Option. + { + let path = path.join("woog_option"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let woog_option: (WoogOption, SystemTime) = serde_json::from_reader(reader)?; + store.woog_option.insert(woog_option.0.id, woog_option); + } + } + + // Load Ownership. + { + let path = path.join("ownership"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let ownership: (Ownership, SystemTime) = serde_json::from_reader(reader)?; + store.ownership.insert(ownership.0.id(), ownership); + } + } + + // Load Parameter. + { + let path = path.join("parameter"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let parameter: (Parameter, SystemTime) = serde_json::from_reader(reader)?; + store.parameter.insert(parameter.0.id, parameter); + } + } + + // Load Reference. + { + let path = path.join("reference"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let reference: (Reference, SystemTime) = serde_json::from_reader(reader)?; + store.reference.insert(reference.0.id, reference); + } + } + + // Load Statement. + { + let path = path.join("statement"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let statement: (Statement, SystemTime) = serde_json::from_reader(reader)?; + store.statement.insert(statement.0.id, statement); + } + } + + // Load Structure. + { + let path = path.join("structure"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let structure: (Structure, SystemTime) = serde_json::from_reader(reader)?; + store.structure.insert(structure.0.id, structure); + } + } + + // Load Structure Field. + { + let path = path.join("structure_field"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let structure_field: (StructureField, SystemTime) = + serde_json::from_reader(reader)?; + store + .structure_field + .insert(structure_field.0.id, structure_field); + } + } + + // Load Symbol Table. + { + let path = path.join("symbol_table"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let symbol_table: (SymbolTable, SystemTime) = serde_json::from_reader(reader)?; + store.symbol_table.insert(symbol_table.0.id, symbol_table); + } + } + + // Load Time Stamp. + { + let path = path.join("time_stamp"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let time_stamp: (TimeStamp, SystemTime) = serde_json::from_reader(reader)?; + store.time_stamp.insert(time_stamp.0.id, time_stamp); + } + } + + // Load Value. + { + let path = path.join("x_value"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let x_value: (XValue, SystemTime) = serde_json::from_reader(reader)?; + store.x_value.insert(x_value.0.id, x_value); + } + } + + // Load Variable. + { + let path = path.join("variable"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let variable: (Variable, SystemTime) = serde_json::from_reader(reader)?; + store.variable.insert(variable.0.id, variable); + } + } + + // Load Visibility. + { + let path = path.join("visibility"); + let entries = fs::read_dir(path)?; + for entry in entries { + let entry = entry?; + let path = entry.path(); + let file = fs::File::open(path)?; + let reader = io::BufReader::new(file); + let visibility: (Visibility, SystemTime) = serde_json::from_reader(reader)?; + store.visibility.insert(visibility.0.id(), visibility); + } + } + + Ok(store) + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/woog_single/types.rs b/src/v2/woog_single/types.rs new file mode 100644 index 00000000..0d09c416 --- /dev/null +++ b/src/v2/woog_single/types.rs @@ -0,0 +1,95 @@ +//! Domain for generating code. +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"v2::woog_single-module-definition-file"}}} +pub mod access; +pub mod block; +pub mod borrowed; +pub mod call; +pub mod constant; +pub mod enumeration; +pub mod enumeration_field; +pub mod expression; +pub mod expression_statement; +pub mod field; +pub mod function; +pub mod generation_unit; +pub mod grace_type; +pub mod implementation; +pub mod item; +pub mod krate; +pub mod literal; +pub mod local; +pub mod mutable; +pub mod object_method; +pub mod owned; +pub mod ownership; +pub mod parameter; +pub mod private; +pub mod public; +pub mod reference; +pub mod statement; +pub mod structure; +pub mod structure_field; +pub mod symbol_table; +pub mod time_stamp; +pub mod usize; +pub mod variable; +pub mod visibility; +pub mod woog_option; +pub mod x_let; +pub mod x_macro; +pub mod x_value; + +pub use crate::v2::woog_single::access::Access; +pub use crate::v2::woog_single::block::Block; +pub use crate::v2::woog_single::borrowed::Borrowed; +pub use crate::v2::woog_single::borrowed::BORROWED; +pub use crate::v2::woog_single::call::Call; +pub use crate::v2::woog_single::constant::Constant; +pub use crate::v2::woog_single::enumeration::Enumeration; +pub use crate::v2::woog_single::enumeration_field::EnumerationField; +pub use crate::v2::woog_single::expression::Expression; +pub use crate::v2::woog_single::expression_statement::ExpressionStatement; +pub use crate::v2::woog_single::expression_statement::EXPRESSION_STATEMENT; +pub use crate::v2::woog_single::field::Field; +pub use crate::v2::woog_single::function::Function; +pub use crate::v2::woog_single::function::FunctionEnum; +pub use crate::v2::woog_single::generation_unit::GenerationUnit; +pub use crate::v2::woog_single::grace_type::GraceType; +pub use crate::v2::woog_single::implementation::Implementation; +pub use crate::v2::woog_single::implementation::IMPLEMENTATION; +pub use crate::v2::woog_single::item::Item; +pub use crate::v2::woog_single::krate::Krate; +pub use crate::v2::woog_single::krate::KRATE; +pub use crate::v2::woog_single::literal::Literal; +pub use crate::v2::woog_single::literal::LITERAL; +pub use crate::v2::woog_single::local::Local; +pub use crate::v2::woog_single::mutable::Mutable; +pub use crate::v2::woog_single::mutable::MUTABLE; +pub use crate::v2::woog_single::object_method::ObjectMethod; +pub use crate::v2::woog_single::owned::Owned; +pub use crate::v2::woog_single::owned::OWNED; +pub use crate::v2::woog_single::ownership::Ownership; +pub use crate::v2::woog_single::parameter::Parameter; +pub use crate::v2::woog_single::private::Private; +pub use crate::v2::woog_single::private::PRIVATE; +pub use crate::v2::woog_single::public::Public; +pub use crate::v2::woog_single::public::PUBLIC; +pub use crate::v2::woog_single::reference::Reference; +pub use crate::v2::woog_single::statement::Statement; +pub use crate::v2::woog_single::statement::StatementEnum; +pub use crate::v2::woog_single::structure::Structure; +pub use crate::v2::woog_single::structure_field::StructureField; +pub use crate::v2::woog_single::symbol_table::SymbolTable; +pub use crate::v2::woog_single::time_stamp::TimeStamp; +pub use crate::v2::woog_single::usize::Usize; +pub use crate::v2::woog_single::usize::USIZE; +pub use crate::v2::woog_single::variable::Variable; +pub use crate::v2::woog_single::variable::VariableEnum; +pub use crate::v2::woog_single::visibility::Visibility; +pub use crate::v2::woog_single::woog_option::WoogOption; +pub use crate::v2::woog_single::x_let::XLet; +pub use crate::v2::woog_single::x_macro::XMacro; +pub use crate::v2::woog_single::x_macro::X_MACRO; +pub use crate::v2::woog_single::x_value::XValue; +pub use crate::v2::woog_single::x_value::XValueEnum; +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/access.rs b/src/v2/woog_single/types/access.rs new file mode 100644 index 00000000..9ad62004 --- /dev/null +++ b/src/v2/woog_single/types/access.rs @@ -0,0 +1,71 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"access-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::ownership::Ownership; +use crate::v2::woog_single::types::visibility::Visibility; +use crate::v2::woog_single::types::x_value::XValue; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-struct-documentation"}}} +/// Value Access +/// +/// This is what I'm calling the combined ideas of mutability and visibility. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Access { + pub id: Uuid, + /// R15: [`Access`] 'has' [`Ownership`] + pub ownership: Uuid, + /// R14: [`Access`] 'has' [`Visibility`] + pub visibility: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-implementation"}}} +impl Access { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-struct-impl-new"}}} + /// Inter a new 'Access' in the store, and return it's `id`. + pub fn new( + ownership: &Ownership, + visibility: &Visibility, + store: &mut WoogSingleStore, + ) -> Access { + let id = Uuid::new_v4(); + let new = Access { + id, + ownership: ownership.id(), + visibility: visibility.id(), + }; + store.inter_access(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-struct-impl-nav-forward-to-ownership"}}} + /// Navigate to [`Ownership`] across R15(1-*) + pub fn r15_ownership<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Ownership> { + vec![store.exhume_ownership(&self.ownership).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-struct-impl-nav-forward-to-visibility"}}} + /// Navigate to [`Visibility`] across R14(1-*) + pub fn r14_visibility<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Visibility> { + vec![store.exhume_visibility(&self.visibility).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"access-struct-impl-nav-backward-1_M-to-x_value"}}} + /// Navigate to [`XValue`] across R16(1-M) + pub fn r16_x_value<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&XValue> { + store + .iter_x_value() + .filter(|x_value| x_value.access == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/block.rs b/src/v2/woog_single/types/block.rs new file mode 100644 index 00000000..fdb75abb --- /dev/null +++ b/src/v2/woog_single/types/block.rs @@ -0,0 +1,77 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"block-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::expression::Expression; +use crate::v2::woog_single::types::object_method::ObjectMethod; +use crate::v2::woog_single::types::statement::Statement; +use crate::v2::woog_single::types::symbol_table::SymbolTable; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-struct-documentation"}}} +/// A Block Expression +/// +/// This is a block of code, you know, between `{` and `}`. See the [reference](https://doc.rust +/// -lang.org/reference/expressions/block-expr.html). +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Block { + pub id: Uuid, + pub seed: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-implementation"}}} +impl Block { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-struct-impl-new"}}} + /// Inter a new 'Block' in the store, and return it's `id`. + pub fn new(seed: Uuid, store: &mut WoogSingleStore) -> Block { + let id = Uuid::new_v4(); + let new = Block { id, seed }; + store.inter_block(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-struct-impl-nav-backward-cond-to-object_method"}}} + /// Navigate to [`ObjectMethod`] across R23(1-1c) + pub fn r23c_object_method<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&ObjectMethod> { + let object_method = store + .iter_object_method() + .find(|object_method| object_method.block == self.id); + match object_method { + Some(ref object_method) => vec![object_method], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-struct-impl-nav-backward-1_M-to-statement"}}} + /// Navigate to [`Statement`] across R12(1-M) + pub fn r12_statement<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Statement> { + store + .iter_statement() + .filter(|statement| statement.block == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-struct-impl-nav-backward-one-to-symbol_table"}}} + /// Navigate to [`SymbolTable`] across R24(1-1) + pub fn r24_symbol_table<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&SymbolTable> { + vec![store + .iter_symbol_table() + .find(|symbol_table| symbol_table.block == self.id) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"block-impl-nav-subtype-to-supertype-expression"}}} + // Navigate to [`Expression`] across R10(isa) + pub fn r10_expression<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Expression> { + vec![store.exhume_expression(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/borrowed.rs b/src/v2/woog_single/types/borrowed.rs new file mode 100644 index 00000000..c98f071f --- /dev/null +++ b/src/v2/woog_single/types/borrowed.rs @@ -0,0 +1,37 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"borrowed-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"borrowed-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"borrowed-const-documentation"}}} +/// Borrowed +/// +/// The type is declared as borrowed. +/// +/// ❗️{"singleton_object": true} +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"borrowed-const-definition"}}} +pub const BORROWED: Uuid = uuid!["4ccd6011-dbef-5503-9015-e5c139895e54"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Borrowed; + +impl Borrowed { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + BORROWED + } +} + +impl Default for Borrowed { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/call.rs b/src/v2/woog_single/types/call.rs new file mode 100644 index 00000000..18767cf2 --- /dev/null +++ b/src/v2/woog_single/types/call.rs @@ -0,0 +1,55 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"call-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::expression::Expression; +use crate::v2::woog_single::types::object_method::ObjectMethod; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-struct-documentation"}}} +/// A Function Call +/// +/// This is [formally](https://doc.rust-lang.org/reference/expressions/call-expr.html) a call +/// expression. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Call { + pub id: Uuid, + /// R19: [`Call`] 'invokes' [`ObjectMethod`] + pub method: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-implementation"}}} +impl Call { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-struct-impl-new"}}} + /// Inter a new 'Call' in the store, and return it's `id`. + pub fn new(method: &ObjectMethod, store: &mut WoogSingleStore) -> Call { + let id = Uuid::new_v4(); + let new = Call { + id, + method: method.id, + }; + store.inter_call(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-struct-impl-nav-forward-to-method"}}} + /// Navigate to [`ObjectMethod`] across R19(1-*) + pub fn r19_object_method<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&ObjectMethod> { + vec![store.exhume_object_method(&self.method).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"call-impl-nav-subtype-to-supertype-expression"}}} + // Navigate to [`Expression`] across R10(isa) + pub fn r10_expression<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Expression> { + vec![store.exhume_expression(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/constant.rs b/src/v2/woog_single/types/constant.rs new file mode 100644 index 00000000..77c627cd --- /dev/null +++ b/src/v2/woog_single/types/constant.rs @@ -0,0 +1,43 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"constant-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"constant-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::item::Item; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"constant-struct-documentation"}}} +/// A Constant +/// +/// This is an inviolable memory, of a certain type. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"constant-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Constant { + pub id: Uuid, + pub name: String, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"constant-implementation"}}} +impl Constant { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"constant-struct-impl-new"}}} + /// Inter a new 'Constant' in the store, and return it's `id`. + pub fn new(name: String, store: &mut WoogSingleStore) -> Constant { + let id = Uuid::new_v4(); + let new = Constant { id, name }; + store.inter_constant(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"constant-impl-nav-subtype-to-supertype-item"}}} + // Navigate to [`Item`] across R26(isa) + pub fn r26_item<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Item> { + vec![store.exhume_item(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/enumeration.rs b/src/v2/woog_single/types/enumeration.rs new file mode 100644 index 00000000..60f15712 --- /dev/null +++ b/src/v2/woog_single/types/enumeration.rs @@ -0,0 +1,58 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"enumeration-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::enumeration_field::EnumerationField; +use crate::v2::woog_single::types::item::Item; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-struct-documentation"}}} +/// An Enumerated Data Type +/// +/// This has fields like a structure, but it's only allowed to contain a +/// single value at a time. This is also refered to as an algebraic +/// data type. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Enumeration { + pub id: Uuid, + pub name: String, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-implementation"}}} +impl Enumeration { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-struct-impl-new"}}} + /// Inter a new 'Enumeration' in the store, and return it's `id`. + pub fn new(name: String, store: &mut WoogSingleStore) -> Enumeration { + let id = Uuid::new_v4(); + let new = Enumeration { id, name }; + store.inter_enumeration(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-struct-impl-nav-backward-assoc-many-to-enumeration_field"}}} + /// Navigate to [`EnumerationField`] across R28(1-M) + pub fn r28_enumeration_field<'a>( + &'a self, + store: &'a WoogSingleStore, + ) -> Vec<&EnumerationField> { + store + .iter_enumeration_field() + .filter(|enumeration_field| enumeration_field.field == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration-impl-nav-subtype-to-supertype-item"}}} + // Navigate to [`Item`] across R26(isa) + pub fn r26_item<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Item> { + vec![store.exhume_item(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/enumeration_field.rs b/src/v2/woog_single/types/enumeration_field.rs new file mode 100644 index 00000000..cc75f72a --- /dev/null +++ b/src/v2/woog_single/types/enumeration_field.rs @@ -0,0 +1,59 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"enumeration_field-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::enumeration::Enumeration; +use crate::v2::woog_single::types::field::Field; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-struct-documentation"}}} +/// A Field in an Enumeration +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct EnumerationField { + pub id: Uuid, + /// R28: [`Enumeration`] '🚧 Comments are out of order — see sarzak#14.' [`Enumeration`] + pub field: Uuid, + /// R28: [`Field`] '🚧 Comments are out of order — see sarzak#14.' [`Field`] + pub woog_enum: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-implementation"}}} +impl EnumerationField { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-struct-impl-new"}}} + /// Inter a new 'Enumeration Field' in the store, and return it's `id`. + pub fn new( + field: &Enumeration, + woog_enum: &Field, + store: &mut WoogSingleStore, + ) -> EnumerationField { + let id = Uuid::new_v4(); + let new = EnumerationField { + id, + field: field.id, + woog_enum: woog_enum.id, + }; + store.inter_enumeration_field(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-struct-impl-nav-forward-assoc-to-field"}}} + /// Navigate to [`Enumeration`] across R28(1-*) + pub fn r28_enumeration<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Enumeration> { + vec![store.exhume_enumeration(&self.field).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"enumeration_field-struct-impl-nav-forward-assoc-to-woog_enum"}}} + /// Navigate to [`Field`] across R28(1-*) + pub fn r28_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Field> { + vec![store.exhume_field(&self.woog_enum).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/expression.rs b/src/v2/woog_single/types/expression.rs new file mode 100644 index 00000000..7cfa84f9 --- /dev/null +++ b/src/v2/woog_single/types/expression.rs @@ -0,0 +1,91 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"expression-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-use-statements"}}} +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +use crate::v2::woog_single::types::block::Block; +use crate::v2::woog_single::types::call::Call; +use crate::v2::woog_single::types::literal::LITERAL; +use crate::v2::woog_single::types::x_let::XLet; +use crate::v2::woog_single::types::x_value::XValue; +use crate::v2::woog_single::types::x_value::XValueEnum; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-enum-documentation"}}} +/// An expression +/// +/// An expression produces a value. There are all sorts of expressions, and I'm only going to +/// cover a very few for now. +/// +/// The expressions here roughly align with what's found in [rust](https://doc.rust-lang.org +/// /reference/expressions.html). +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-enum-definition"}}} +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum Expression { + Block(Uuid), + Call(Uuid), + Literal(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-implementation"}}} +impl Expression { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-new-impl"}}} + /// Create a new instance of Expression::Block + pub fn new_block(block: &Block, store: &mut WoogSingleStore) -> Self { + let new = Self::Block(block.id); + store.inter_expression(new.clone()); + new + } // wtf? + + /// Create a new instance of Expression::Call + pub fn new_call(call: &Call, store: &mut WoogSingleStore) -> Self { + let new = Self::Call(call.id); + store.inter_expression(new.clone()); + new + } // wtf? + + /// Create a new instance of Expression::Literal + pub fn new_literal() -> Self { + // This is already in the store, see associated function `new` above. + Self::Literal(LITERAL) + } + + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-get-id-impl"}}} + pub fn id(&self) -> Uuid { + match self { + Self::Block(id) => *id, + Self::Call(id) => *id, + Self::Literal(id) => *id, + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-struct-impl-nav-backward-1_M-to-x_let"}}} + /// Navigate to [`XLet`] across R18(1-M) + pub fn r18_x_let<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&XLet> { + store + .iter_x_let() + .filter(|x_let| x_let.expression == self.id()) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression-impl-nav-subtype-to-supertype-x_value"}}} + // Navigate to [`XValue`] across R7(isa) + pub fn r7_x_value<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&XValue> { + vec![store + .iter_x_value() + .find(|x_value| { + if let XValueEnum::Expression(id) = x_value.subtype { + id == self.id() + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/expression_statement.rs b/src/v2/woog_single/types/expression_statement.rs new file mode 100644 index 00000000..e200f2d7 --- /dev/null +++ b/src/v2/woog_single/types/expression_statement.rs @@ -0,0 +1,39 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"expression_statement-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression_statement-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression_statement-const-documentation"}}} +/// Expression Statement +/// +/// A [statement](https://doc.rust-lang.org/reference/statements.html#expression-statements +/// ) used for it's side effects. +/// +/// I'd prefer to call this just `Expression`, but that would break things. Here's an [issue +/// to address the limitation.](https://git.uberfoo.com/sarzak/grace/-/issues/44) +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"expression_statement-const-definition"}}} +pub const EXPRESSION_STATEMENT: Uuid = uuid!["7cb01522-5a5c-5eff-9904-590a57d7b8c5"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct ExpressionStatement; + +impl ExpressionStatement { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + EXPRESSION_STATEMENT + } +} + +impl Default for ExpressionStatement { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/field.rs b/src/v2/woog_single/types/field.rs new file mode 100644 index 00000000..b3e1105c --- /dev/null +++ b/src/v2/woog_single/types/field.rs @@ -0,0 +1,79 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"field-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::enumeration_field::EnumerationField; +use crate::v2::woog_single::types::grace_type::GraceType; +use crate::v2::woog_single::types::structure_field::StructureField; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-struct-documentation"}}} +/// A Field +/// +/// A field is a named part of a data structure (an [`Enumeration`] or a [`Structure`] of a +/// given [`GraceType`]. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Field { + pub id: Uuid, + pub name: String, + /// R29: [`Field`] 'is of a' [`GraceType`] + pub ty: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-implementation"}}} +impl Field { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-struct-impl-new"}}} + /// Inter a new 'Field' in the store, and return it's `id`. + pub fn new(name: String, ty: &GraceType, store: &mut WoogSingleStore) -> Field { + let id = Uuid::new_v4(); + let new = Field { + id, + name, + ty: ty.id(), + }; + store.inter_field(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-struct-impl-nav-forward-to-ty"}}} + /// Navigate to [`GraceType`] across R29(1-*) + pub fn r29_grace_type<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&GraceType> { + vec![store.exhume_grace_type(&self.ty).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-struct-impl-nav-backward-assoc-one-cond-to-structure_field"}}} + /// Navigate to [`StructureField`] across R27(1-1c) + pub fn r27_structure_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&StructureField> { + let structure_field = store + .iter_structure_field() + .find(|structure_field| structure_field.woog_struct == self.id); + match structure_field { + Some(structure_field) => vec![structure_field], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"field-struct-impl-nav-backward-assoc-one-cond-to-enumeration_field"}}} + /// Navigate to [`EnumerationField`] across R28(1-1c) + pub fn r28_enumeration_field<'a>( + &'a self, + store: &'a WoogSingleStore, + ) -> Vec<&EnumerationField> { + let enumeration_field = store + .iter_enumeration_field() + .find(|enumeration_field| enumeration_field.woog_enum == self.id); + match enumeration_field { + Some(enumeration_field) => vec![enumeration_field], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/function.rs b/src/v2/woog_single/types/function.rs new file mode 100644 index 00000000..9f964b1a --- /dev/null +++ b/src/v2/woog_single/types/function.rs @@ -0,0 +1,75 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"function-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::item::Item; +use crate::v2::woog_single::types::object_method::ObjectMethod; +use crate::v2::woog_single::types::parameter::Parameter; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-hybrid-documentation"}}} +/// A function +/// +/// This is a plain old function, distinct from an [`Object Method`]. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-hybrid-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Function { + pub subtype: FunctionEnum, + pub description: String, + pub id: Uuid, + pub name: String, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-hybrid-enum-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum FunctionEnum { + ObjectMethod(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-implementation"}}} +impl Function { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-struct-impl-new_object_method"}}} + /// Inter a new Function in the store, and return it's `id`. + pub fn new_object_method( + description: String, + name: String, + subtype: &ObjectMethod, + store: &mut WoogSingleStore, + ) -> Function { + let id = Uuid::new_v4(); + let new = Function { + description: description, + name: name, + subtype: FunctionEnum::ObjectMethod(subtype.id), + id, + }; + store.inter_function(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-struct-impl-nav-backward-one-bi-cond-to-parameter"}}} + /// Navigate to [`Parameter`] across R5(1c-1c) + pub fn r5c_parameter<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Parameter> { + let parameter = store + .iter_parameter() + .find(|parameter| parameter.function == Some(self.id)); + match parameter { + Some(ref parameter) => vec![parameter], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"function-impl-nav-subtype-to-supertype-item"}}} + // Navigate to [`Item`] across R26(isa) + pub fn r26_item<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Item> { + vec![store.exhume_item(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/generation_unit.rs b/src/v2/woog_single/types/generation_unit.rs new file mode 100644 index 00000000..c7fdc7ac --- /dev/null +++ b/src/v2/woog_single/types/generation_unit.rs @@ -0,0 +1,56 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"generation_unit-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"generation_unit-use-statements"}}} +use uuid::Uuid; + +use crate::v2::sarzak_single::types::object::Object; +use crate::v2::woog_single::types::time_stamp::TimeStamp; +use serde::{Deserialize, Serialize}; + +use crate::v2::sarzak_single::store::ObjectStore as SarzakStore; +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"generation_unit-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct GenerationUnit { + pub id: Uuid, + /// R21: [`GenerationUnit`] 'is created at' [`TimeStamp`] + pub creation_time: Uuid, + /// R22: [`GenerationUnit`] 'is based on an' [`Object`] + pub object: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"generation_unit-implementation"}}} +impl GenerationUnit { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"generation_unit-struct-impl-new"}}} + /// Inter a new 'Generation Unit' in the store, and return it's `id`. + pub fn new( + creation_time: &TimeStamp, + object: &Object, + store: &mut WoogSingleStore, + ) -> GenerationUnit { + let id = Uuid::new_v4(); + let new = GenerationUnit { + id, + creation_time: creation_time.id, + object: object.id, + }; + store.inter_generation_unit(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"generation_unit-struct-impl-nav-forward-to-creation_time"}}} + /// Navigate to [`TimeStamp`] across R21(1-*) + pub fn r21_time_stamp<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&TimeStamp> { + vec![store.exhume_time_stamp(&self.creation_time).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"generation_unit-struct-impl-nav-forward-to-object"}}} + /// Navigate to [`Object`] across R22(1-*) + pub fn r22_object<'a>(&'a self, store: &'a SarzakStore) -> Vec<&Object> { + vec![store.exhume_object(&self.object).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/grace_type.rs b/src/v2/woog_single/types/grace_type.rs new file mode 100644 index 00000000..3650befd --- /dev/null +++ b/src/v2/woog_single/types/grace_type.rs @@ -0,0 +1,113 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"grace_type-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-use-statements"}}} +use crate::v2::sarzak::types::ty::Ty; +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +use crate::v2::woog_single::types::field::Field; +use crate::v2::woog_single::types::reference::Reference; +use crate::v2::woog_single::types::time_stamp::TimeStamp; +use crate::v2::woog_single::types::usize::USIZE; +use crate::v2::woog_single::types::woog_option::WoogOption; +use crate::v2::woog_single::types::x_value::XValue; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-enum-documentation"}}} +/// Grace Model Compiler Type +/// +/// The model compiler domain contains at least one type that doesn't make sense within the +/// modeling domain. That type is an object reference. References, in my mind, have no place +/// in a modeling domain. +/// +/// So that's what this is about. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-enum-definition"}}} +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum GraceType { + WoogOption(Uuid), + Reference(Uuid), + TimeStamp(Uuid), + Ty(Uuid), + Usize(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-implementation"}}} +impl GraceType { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-new-impl"}}} + /// Create a new instance of GraceType::WoogOption + pub fn new_woog_option(woog_option: &WoogOption, store: &mut WoogSingleStore) -> Self { + let new = Self::WoogOption(woog_option.id); + store.inter_grace_type(new.clone()); + new + } // wtf? + + /// Create a new instance of GraceType::Reference + pub fn new_reference(reference: &Reference, store: &mut WoogSingleStore) -> Self { + let new = Self::Reference(reference.id); + store.inter_grace_type(new.clone()); + new + } // wtf? + + /// Create a new instance of GraceType::TimeStamp + pub fn new_time_stamp(time_stamp: &TimeStamp, store: &mut WoogSingleStore) -> Self { + let new = Self::TimeStamp(time_stamp.id); + store.inter_grace_type(new.clone()); + new + } // wtf? + + /// Create a new instance of GraceType::Ty + pub fn new_ty(ty: &Ty, store: &mut WoogSingleStore) -> Self { + let new = Self::Ty(ty.id()); + store.inter_grace_type(new.clone()); + new + } // wtf? + + /// Create a new instance of GraceType::Usize + pub fn new_usize() -> Self { + // This is already in the store, see associated function `new` above. + Self::Usize(USIZE) + } + + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-get-id-impl"}}} + pub fn id(&self) -> Uuid { + match self { + Self::WoogOption(id) => *id, + Self::Reference(id) => *id, + Self::TimeStamp(id) => *id, + Self::Ty(id) => *id, + Self::Usize(id) => *id, + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-struct-impl-nav-backward-1_M-to-field"}}} + /// Navigate to [`Field`] across R29(1-M) + pub fn r29_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Field> { + store + .iter_field() + .filter(|field| field.ty == self.id()) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-struct-impl-nav-backward-1_M-to-woog_option"}}} + /// Navigate to [`WoogOption`] across R20(1-M) + pub fn r20_woog_option<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&WoogOption> { + store + .iter_woog_option() + .filter(|woog_option| woog_option.ty == self.id()) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"grace_type-struct-impl-nav-backward-1_M-to-x_value"}}} + /// Navigate to [`XValue`] across R3(1-M) + pub fn r3_x_value<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&XValue> { + store + .iter_x_value() + .filter(|x_value| x_value.ty == self.id()) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/implementation.rs b/src/v2/woog_single/types/implementation.rs new file mode 100644 index 00000000..a7031394 --- /dev/null +++ b/src/v2/woog_single/types/implementation.rs @@ -0,0 +1,35 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"implementation-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"implementation-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"implementation-const-documentation"}}} +/// Dynamic Object Association +/// +/// This scopes functions and constants to a [`Structure`] or an [`Enumeration`]. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"implementation-const-definition"}}} +pub const IMPLEMENTATION: Uuid = uuid!["d9423bdc-1217-5acc-9083-e13adccd9258"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Implementation; + +impl Implementation { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + IMPLEMENTATION + } +} + +impl Default for Implementation { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/item.rs b/src/v2/woog_single/types/item.rs new file mode 100644 index 00000000..2967cf05 --- /dev/null +++ b/src/v2/woog_single/types/item.rs @@ -0,0 +1,99 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"item-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-use-statements"}}} +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +use crate::v2::woog_single::types::constant::Constant; +use crate::v2::woog_single::types::enumeration::Enumeration; +use crate::v2::woog_single::types::function::Function; +use crate::v2::woog_single::types::implementation::IMPLEMENTATION; +use crate::v2::woog_single::types::statement::Statement; +use crate::v2::woog_single::types::statement::StatementEnum; +use crate::v2::woog_single::types::structure::Structure; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-enum-documentation"}}} +/// An Item +/// +/// This [entails a lot](https://doc.rust-lang.org/reference/items.html) of syntax that I'm +/// just rolling up into one for now. We'll see for how long I can manage to get away with this +/// . 😎 +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-enum-definition"}}} +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum Item { + Constant(Uuid), + Enumeration(Uuid), + Function(Uuid), + Implementation(Uuid), + Structure(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-implementation"}}} +impl Item { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-new-impl"}}} + /// Create a new instance of Item::Constant + pub fn new_constant(constant: &Constant, store: &mut WoogSingleStore) -> Self { + let new = Self::Constant(constant.id); + store.inter_item(new.clone()); + new + } // wtf? + + /// Create a new instance of Item::Enumeration + pub fn new_enumeration(enumeration: &Enumeration, store: &mut WoogSingleStore) -> Self { + let new = Self::Enumeration(enumeration.id); + store.inter_item(new.clone()); + new + } // wtf? + + /// Create a new instance of Item::Function + pub fn new_function(function: &Function, store: &mut WoogSingleStore) -> Self { + let new = Self::Function(function.id); + store.inter_item(new.clone()); + new + } // wtf? + + /// Create a new instance of Item::Implementation + pub fn new_implementation() -> Self { + // This is already in the store, see associated function `new` above. + Self::Implementation(IMPLEMENTATION) + } + + /// Create a new instance of Item::Structure + pub fn new_structure(structure: &Structure, store: &mut WoogSingleStore) -> Self { + let new = Self::Structure(structure.id); + store.inter_item(new.clone()); + new + } // wtf? + + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-get-id-impl"}}} + pub fn id(&self) -> Uuid { + match self { + Self::Constant(id) => *id, + Self::Enumeration(id) => *id, + Self::Function(id) => *id, + Self::Implementation(id) => *id, + Self::Structure(id) => *id, + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"item-impl-nav-subtype-to-supertype-statement"}}} + // Navigate to [`Statement`] across R11(isa) + pub fn r11_statement<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Statement> { + vec![store + .iter_statement() + .find(|statement| { + if let StatementEnum::Item(id) = statement.subtype { + id == self.id() + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/krate.rs b/src/v2/woog_single/types/krate.rs new file mode 100644 index 00000000..36dc786c --- /dev/null +++ b/src/v2/woog_single/types/krate.rs @@ -0,0 +1,37 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"krate-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"krate-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"krate-const-documentation"}}} +/// Crate Visibility +/// +/// The item is visibile within the crate. +/// +/// ❗️{"singleton_object": true} +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"krate-const-definition"}}} +pub const KRATE: Uuid = uuid!["7de289c9-3492-507f-b3ab-9cdbecb7e4a3"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Krate; + +impl Krate { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + KRATE + } +} + +impl Default for Krate { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/literal.rs b/src/v2/woog_single/types/literal.rs new file mode 100644 index 00000000..18105550 --- /dev/null +++ b/src/v2/woog_single/types/literal.rs @@ -0,0 +1,35 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"literal-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"literal-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"literal-const-documentation"}}} +/// A Literal Expression +/// +/// It's literally, a literal. Like that? 🤣 +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"literal-const-definition"}}} +pub const LITERAL: Uuid = uuid!["791d5acd-5374-5fde-b181-dd1e0c005a02"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Literal; + +impl Literal { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + LITERAL + } +} + +impl Default for Literal { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/local.rs b/src/v2/woog_single/types/local.rs new file mode 100644 index 00000000..83107600 --- /dev/null +++ b/src/v2/woog_single/types/local.rs @@ -0,0 +1,55 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"local-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"local-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::variable::Variable; +use crate::v2::woog_single::types::variable::VariableEnum; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"local-struct-documentation"}}} +/// A Local Variable +/// +/// A plain old variable. It's got a name. +/// +/// At some point I'm going to have to start thinking about scopes. 🤔 +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"local-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Local { + pub id: Uuid, + pub seed: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"local-implementation"}}} +impl Local { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"local-struct-impl-new"}}} + /// Inter a new 'Local' in the store, and return it's `id`. + pub fn new(seed: Uuid, store: &mut WoogSingleStore) -> Local { + let id = Uuid::new_v4(); + let new = Local { id, seed }; + store.inter_local(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"local-impl-nav-subtype-to-supertype-variable"}}} + // Navigate to [`Variable`] across R8(isa) + pub fn r8_variable<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Variable> { + vec![store + .iter_variable() + .find(|variable| { + if let VariableEnum::Local(id) = variable.subtype { + id == self.id + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/mutable.rs b/src/v2/woog_single/types/mutable.rs new file mode 100644 index 00000000..b4663610 --- /dev/null +++ b/src/v2/woog_single/types/mutable.rs @@ -0,0 +1,37 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"mutable-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"mutable-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"mutable-const-documentation"}}} +/// Mutable +/// +/// The type is declared as `mut`. +/// +/// ❗️{"singleton_object": true} +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"mutable-const-definition"}}} +pub const MUTABLE: Uuid = uuid!["1a837379-51fe-51a5-baf1-e7bd8c22ef7a"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Mutable; + +impl Mutable { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + MUTABLE + } +} + +impl Default for Mutable { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/object_method.rs b/src/v2/woog_single/types/object_method.rs new file mode 100644 index 00000000..d099ed3d --- /dev/null +++ b/src/v2/woog_single/types/object_method.rs @@ -0,0 +1,95 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"object_method-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-use-statements"}}} +use uuid::Uuid; + +use crate::v2::sarzak_single::types::object::Object; +use crate::v2::woog_single::types::block::Block; +use crate::v2::woog_single::types::call::Call; +use crate::v2::woog_single::types::function::Function; +use crate::v2::woog_single::types::function::FunctionEnum; +use serde::{Deserialize, Serialize}; + +use crate::v2::sarzak_single::store::ObjectStore as SarzakStore; +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-struct-documentation"}}} +/// Method +/// +/// This represents a function's signature. We don't (yet) care about the body of the function +/// . We are however very interested in it's type, which implies parameters and their types, +/// as well as our return type. +/// +/// Looking at this more closely, I think that this should be related to a parameter list, and +/// the list related to the string of parameters. It may just be a nit, but it does bother me +/// a bit. I'll come back and fix it once it's less troublesome to generate this domain. +/// +/// The function in question is a method, hanging off of an [`Object`][o]. +/// +/// [o][damn, now I need a documentation server]. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct ObjectMethod { + pub id: Uuid, + /// R23: [`ObjectMethod`] 'contains a' [`Block`] + pub block: Uuid, + /// R4: [`ObjectMethod`] 'is scoped to an' [`Object`] + pub object: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-implementation"}}} +impl ObjectMethod { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-struct-impl-new"}}} + /// Inter a new 'Object Method' in the store, and return it's `id`. + pub fn new(block: &Block, object: &Object, store: &mut WoogSingleStore) -> ObjectMethod { + let id = Uuid::new_v4(); + let new = ObjectMethod { + id, + block: block.id, + object: object.id, + }; + store.inter_object_method(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-struct-impl-nav-forward-to-block"}}} + /// Navigate to [`Block`] across R23(1-*) + pub fn r23_block<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Block> { + vec![store.exhume_block(&self.block).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-struct-impl-nav-forward-to-object"}}} + /// Navigate to [`Object`] across R4(1-*) + pub fn r4_object<'a>(&'a self, store: &'a SarzakStore) -> Vec<&Object> { + vec![store.exhume_object(&self.object).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-struct-impl-nav-backward-1_M-to-call"}}} + /// Navigate to [`Call`] across R19(1-M) + pub fn r19_call<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Call> { + store + .iter_call() + .filter(|call| call.method == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"object_method-impl-nav-subtype-to-supertype-function"}}} + // Navigate to [`Function`] across R25(isa) + pub fn r25_function<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Function> { + vec![store + .iter_function() + .find(|function| { + if let FunctionEnum::ObjectMethod(id) = function.subtype { + id == self.id + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/owned.rs b/src/v2/woog_single/types/owned.rs new file mode 100644 index 00000000..cb7a5855 --- /dev/null +++ b/src/v2/woog_single/types/owned.rs @@ -0,0 +1,35 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"owned-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"owned-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"owned-const-documentation"}}} +/// An owned value +/// +/// Someone has to be responsible for it, right? +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"owned-const-definition"}}} +pub const OWNED: Uuid = uuid!["81f5c36f-be98-5d4e-9896-26a8b13653cd"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Owned; + +impl Owned { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + OWNED + } +} + +impl Default for Owned { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/ownership.rs b/src/v2/woog_single/types/ownership.rs new file mode 100644 index 00000000..5f6b1f60 --- /dev/null +++ b/src/v2/woog_single/types/ownership.rs @@ -0,0 +1,69 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"ownership-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-use-statements"}}} +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +use crate::v2::woog_single::types::access::Access; +use crate::v2::woog_single::types::borrowed::BORROWED; +use crate::v2::woog_single::types::mutable::MUTABLE; +use crate::v2::woog_single::types::owned::OWNED; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-enum-documentation"}}} +/// Type Ownership +/// +/// This is tied closely with Rust. There are tthree possible options: owned, mutable and borrowed +/// . +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-enum-definition"}}} +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum Ownership { + Borrowed(Uuid), + Mutable(Uuid), + Owned(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-implementation"}}} +impl Ownership { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-new-impl"}}} + /// Create a new instance of Ownership::Borrowed + pub fn new_borrowed() -> Self { + // This is already in the store, see associated function `new` above. + Self::Borrowed(BORROWED) + } + + /// Create a new instance of Ownership::Mutable + pub fn new_mutable() -> Self { + // This is already in the store, see associated function `new` above. + Self::Mutable(MUTABLE) + } + + /// Create a new instance of Ownership::Owned + pub fn new_owned() -> Self { + // This is already in the store, see associated function `new` above. + Self::Owned(OWNED) + } + + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-get-id-impl"}}} + pub fn id(&self) -> Uuid { + match self { + Self::Borrowed(id) => *id, + Self::Mutable(id) => *id, + Self::Owned(id) => *id, + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"ownership-struct-impl-nav-backward-1_M-to-access"}}} + /// Navigate to [`Access`] across R15(1-M) + pub fn r15_access<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Access> { + store + .iter_access() + .filter(|access| access.ownership == self.id()) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/parameter.rs b/src/v2/woog_single/types/parameter.rs new file mode 100644 index 00000000..e9b3667e --- /dev/null +++ b/src/v2/woog_single/types/parameter.rs @@ -0,0 +1,98 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"parameter-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::function::Function; +use crate::v2::woog_single::types::variable::Variable; +use crate::v2::woog_single::types::variable::VariableEnum; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-struct-documentation"}}} +/// Parameter +/// +/// A parameter is an input to a function. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Parameter { + pub id: Uuid, + pub seed: Uuid, + /// R5: [`Parameter`] 'is used by a' [`Function`] + pub function: Option, + /// R1: [`Parameter`] 'came before' [`Parameter`] + pub next: Option, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-implementation"}}} +impl Parameter { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-struct-impl-new"}}} + /// Inter a new 'Parameter' in the store, and return it's `id`. + pub fn new( + seed: Uuid, + function: Option<&Function>, + next: Option<&Parameter>, + store: &mut WoogSingleStore, + ) -> Parameter { + let id = Uuid::new_v4(); + let new = Parameter { + id, + seed, + function: function.as_ref().map(|function| function.id), + next: next.as_ref().map(|parameter| parameter.id), + }; + store.inter_parameter(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-struct-impl-nav-forward-cond-to-function"}}} + /// Navigate to [`Function`] across R5(1-*c) + pub fn r5_function<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Function> { + match self.function { + Some(ref function) => vec![store.exhume_function(function).unwrap()], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-struct-impl-nav-forward-cond-to-next"}}} + /// Navigate to [`Parameter`] across R1(1-*c) + pub fn r1_parameter<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Parameter> { + match self.next { + Some(ref next) => vec![store.exhume_parameter(next).unwrap()], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-struct-impl-nav-backward-one-bi-cond-to-parameter"}}} + /// Navigate to [`Parameter`] across R1(1c-1c) + pub fn r1c_parameter<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Parameter> { + let parameter = store + .iter_parameter() + .find(|parameter| parameter.next == Some(self.id)); + match parameter { + Some(ref parameter) => vec![parameter], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"parameter-impl-nav-subtype-to-supertype-variable"}}} + // Navigate to [`Variable`] across R8(isa) + pub fn r8_variable<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Variable> { + vec![store + .iter_variable() + .find(|variable| { + if let VariableEnum::Parameter(id) = variable.subtype { + id == self.id + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/private.rs b/src/v2/woog_single/types/private.rs new file mode 100644 index 00000000..cc03a655 --- /dev/null +++ b/src/v2/woog_single/types/private.rs @@ -0,0 +1,35 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"private-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"private-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"private-const-documentation"}}} +/// Private Visibility +/// +/// ❗️{"singleton_object": true} +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"private-const-definition"}}} +pub const PRIVATE: Uuid = uuid!["bb92c265-039b-5f30-94d8-a1367ac0f895"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Private; + +impl Private { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + PRIVATE + } +} + +impl Default for Private { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/public.rs b/src/v2/woog_single/types/public.rs new file mode 100644 index 00000000..2e0c5602 --- /dev/null +++ b/src/v2/woog_single/types/public.rs @@ -0,0 +1,35 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"public-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"public-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"public-const-documentation"}}} +/// Public Visibility +/// +/// ❗️{"singleton_object": true} +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"public-const-definition"}}} +pub const PUBLIC: Uuid = uuid!["9600c3e7-157a-5757-8a05-0eff604b9ba5"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Public; + +impl Public { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + PUBLIC + } +} + +impl Default for Public { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/reference.rs b/src/v2/woog_single/types/reference.rs new file mode 100644 index 00000000..62be9117 --- /dev/null +++ b/src/v2/woog_single/types/reference.rs @@ -0,0 +1,57 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"reference-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-use-statements"}}} +use uuid::Uuid; + +use crate::v2::sarzak_single::types::object::Object; +use crate::v2::woog_single::types::grace_type::GraceType; +use serde::{Deserialize, Serialize}; + +use crate::v2::sarzak_single::store::ObjectStore as SarzakStore; +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-struct-documentation"}}} +/// A Reference +/// +/// Specifically this is a reference to something that was translated from an [`Object`]. In +/// rust that's a `struct` or an `enum`. +/// +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Reference { + pub id: Uuid, + /// R13: [`Reference`] 'points at an' [`Object`] + pub object: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-implementation"}}} +impl Reference { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-struct-impl-new"}}} + /// Inter a new 'Reference' in the store, and return it's `id`. + pub fn new(object: &Object, store: &mut WoogSingleStore) -> Reference { + let id = Uuid::new_v4(); + let new = Reference { + id, + object: object.id, + }; + store.inter_reference(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-struct-impl-nav-forward-to-object"}}} + /// Navigate to [`Object`] across R13(1-*) + pub fn r13_object<'a>(&'a self, store: &'a SarzakStore) -> Vec<&Object> { + vec![store.exhume_object(&self.object).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"reference-impl-nav-subtype-to-supertype-grace_type"}}} + // Navigate to [`GraceType`] across R2(isa) + pub fn r2_grace_type<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&GraceType> { + vec![store.exhume_grace_type(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/statement.rs b/src/v2/woog_single/types/statement.rs new file mode 100644 index 00000000..9ef7a96d --- /dev/null +++ b/src/v2/woog_single/types/statement.rs @@ -0,0 +1,102 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"statement-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::block::Block; +use crate::v2::woog_single::types::expression_statement::EXPRESSION_STATEMENT; +use crate::v2::woog_single::types::item::Item; +use crate::v2::woog_single::types::x_let::XLet; +use crate::v2::woog_single::types::x_macro::X_MACRO; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-hybrid-documentation"}}} +/// A Statement +/// +/// There aren't all that many types of [statement in rust.](https://doc.rust-lang.org/reference +/// /statements.html). +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-hybrid-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Statement { + pub subtype: StatementEnum, + pub id: Uuid, + /// R12: [`Statement`] 'belongs to a' [`Block`] + pub block: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-hybrid-enum-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum StatementEnum { + ExpressionStatement(Uuid), + Item(Uuid), + XLet(Uuid), + XMacro(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-implementation"}}} +impl Statement { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-struct-impl-new_expression_statement"}}} + /// Inter a new Statement in the store, and return it's `id`. + pub fn new_expression_statement(block: &Block, store: &mut WoogSingleStore) -> Statement { + let id = Uuid::new_v4(); + let new = Statement { + block: block.id, + subtype: StatementEnum::ExpressionStatement(EXPRESSION_STATEMENT), + id, + }; + store.inter_statement(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-struct-impl-new_item"}}} + /// Inter a new Statement in the store, and return it's `id`. + pub fn new_item(block: &Block, subtype: &Item, store: &mut WoogSingleStore) -> Statement { + let id = Uuid::new_v4(); + let new = Statement { + block: block.id, + subtype: StatementEnum::Item(subtype.id()), + id, + }; + store.inter_statement(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-struct-impl-new_x_let"}}} + /// Inter a new Statement in the store, and return it's `id`. + pub fn new_x_let(block: &Block, subtype: &XLet, store: &mut WoogSingleStore) -> Statement { + let id = Uuid::new_v4(); + let new = Statement { + block: block.id, + subtype: StatementEnum::XLet(subtype.id), + id, + }; + store.inter_statement(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-struct-impl-new_x_macro"}}} + /// Inter a new Statement in the store, and return it's `id`. + pub fn new_x_macro(block: &Block, store: &mut WoogSingleStore) -> Statement { + let id = Uuid::new_v4(); + let new = Statement { + block: block.id, + subtype: StatementEnum::XMacro(X_MACRO), + id, + }; + store.inter_statement(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"statement-struct-impl-nav-forward-to-block"}}} + /// Navigate to [`Block`] across R12(1-*) + pub fn r12_block<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Block> { + vec![store.exhume_block(&self.block).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/structure.rs b/src/v2/woog_single/types/structure.rs new file mode 100644 index 00000000..fe1f9bc6 --- /dev/null +++ b/src/v2/woog_single/types/structure.rs @@ -0,0 +1,53 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"structure-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::item::Item; +use crate::v2::woog_single::types::structure_field::StructureField; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-struct-documentation"}}} +/// A Data Type +/// +/// A structure is a chunk of memory with named, and typed fields. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Structure { + pub id: Uuid, + pub name: String, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-implementation"}}} +impl Structure { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-struct-impl-new"}}} + /// Inter a new 'Structure' in the store, and return it's `id`. + pub fn new(name: String, store: &mut WoogSingleStore) -> Structure { + let id = Uuid::new_v4(); + let new = Structure { id, name }; + store.inter_structure(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-struct-impl-nav-backward-assoc-many-to-structure_field"}}} + /// Navigate to [`StructureField`] across R27(1-M) + pub fn r27_structure_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&StructureField> { + store + .iter_structure_field() + .filter(|structure_field| structure_field.field == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure-impl-nav-subtype-to-supertype-item"}}} + // Navigate to [`Item`] across R26(isa) + pub fn r26_item<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Item> { + vec![store.exhume_item(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/structure_field.rs b/src/v2/woog_single/types/structure_field.rs new file mode 100644 index 00000000..766e443f --- /dev/null +++ b/src/v2/woog_single/types/structure_field.rs @@ -0,0 +1,84 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"structure_field-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::field::Field; +use crate::v2::woog_single::types::structure::Structure; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-documentation"}}} +/// A Field in a Structure +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct StructureField { + pub id: Uuid, + /// R30: [`StructureField`] 'came before' [`StructureField`] + pub next: Option, + /// R27: [`Field`] '🚧 Comments are out of order — see sarzak#14.' [`Field`] + pub woog_struct: Uuid, + /// R27: [`Structure`] '🚧 Comments are out of order — see sarzak#14.' [`Structure`] + pub field: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-implementation"}}} +impl StructureField { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-impl-new"}}} + /// Inter a new 'Structure Field' in the store, and return it's `id`. + pub fn new( + next: Option<&StructureField>, + woog_struct: &Field, + field: &Structure, + store: &mut WoogSingleStore, + ) -> StructureField { + let id = Uuid::new_v4(); + let new = StructureField { + id, + next: next.as_ref().map(|structure_field| structure_field.id), + woog_struct: woog_struct.id, + field: field.id, + }; + store.inter_structure_field(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-impl-nav-forward-cond-to-next"}}} + /// Navigate to [`StructureField`] across R30(1-*c) + pub fn r30_structure_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&StructureField> { + match self.next { + Some(ref next) => vec![store.exhume_structure_field(next).unwrap()], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-impl-nav-backward-one-bi-cond-to-structure_field"}}} + /// Navigate to [`StructureField`] across R30(1c-1c) + pub fn r30c_structure_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&StructureField> { + let structure_field = store + .iter_structure_field() + .find(|structure_field| structure_field.next == Some(self.id)); + match structure_field { + Some(ref structure_field) => vec![structure_field], + None => Vec::new(), + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-impl-nav-forward-assoc-to-woog_struct"}}} + /// Navigate to [`Field`] across R27(1-*) + pub fn r27_field<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Field> { + vec![store.exhume_field(&self.woog_struct).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"structure_field-struct-impl-nav-forward-assoc-to-field"}}} + /// Navigate to [`Structure`] across R27(1-*) + pub fn r27_structure<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Structure> { + vec![store.exhume_structure(&self.field).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/symbol_table.rs b/src/v2/woog_single/types/symbol_table.rs new file mode 100644 index 00000000..61176e4f --- /dev/null +++ b/src/v2/woog_single/types/symbol_table.rs @@ -0,0 +1,57 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"symbol_table-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::block::Block; +use crate::v2::woog_single::types::variable::Variable; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-struct-documentation"}}} +/// Local variable symbol table +/// +/// This is how we know what's available, and what it's type is. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct SymbolTable { + pub id: Uuid, + /// R24: [`SymbolTable`] 'co-exists with a' [`Block`] + pub block: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-implementation"}}} +impl SymbolTable { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-struct-impl-new"}}} + /// Inter a new 'Symbol Table' in the store, and return it's `id`. + pub fn new(block: &Block, store: &mut WoogSingleStore) -> SymbolTable { + let id = Uuid::new_v4(); + let new = SymbolTable { + id, + block: block.id, + }; + store.inter_symbol_table(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-struct-impl-nav-forward-to-block"}}} + /// Navigate to [`Block`] across R24(1-*) + pub fn r24_block<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Block> { + vec![store.exhume_block(&self.block).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"symbol_table-struct-impl-nav-backward-1_M-to-variable"}}} + /// Navigate to [`Variable`] across R20(1-M) + pub fn r20_variable<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Variable> { + store + .iter_variable() + .filter(|variable| variable.symbol_table == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/time_stamp.rs b/src/v2/woog_single/types/time_stamp.rs new file mode 100644 index 00000000..5edf71ad --- /dev/null +++ b/src/v2/woog_single/types/time_stamp.rs @@ -0,0 +1,39 @@ +//! Time Stamp External Entity +//! +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"time_stamp-ee-use-statements"}}} +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +use crate::v2::woog_single::UUID_NS; +use serde::{Deserialize, Serialize}; +use std::time::SystemTime; +use uuid::Uuid; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"time_stamp-ee-documentation"}}} +/// A timestamp with nanosecond precision +/// +/// There are all sorts of caveats about using this in the documentation. I should include +/// a pointer to it here. +/// +/// 🐶 {"external_entity": {"name": "SystemTime", "ctor": "now", "path": "std::time"}} +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"time_stamp-ee-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct TimeStamp { + pub id: Uuid, + inner: SystemTime, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"time_stamp-ee-impl"}}} +impl TimeStamp { + pub fn new(store: &mut WoogSingleStore) -> TimeStamp { + let inner = SystemTime::now(); + let id = Uuid::new_v5(&UUID_NS, format!("{:?}", inner).as_bytes()); + let new = TimeStamp { + id: id, + inner: inner, + }; + store.inter_time_stamp(new.clone()); + new + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} diff --git a/src/v2/woog_single/types/usize.rs b/src/v2/woog_single/types/usize.rs new file mode 100644 index 00000000..4bbbe102 --- /dev/null +++ b/src/v2/woog_single/types/usize.rs @@ -0,0 +1,33 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"usize-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"usize-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"usize-const-documentation"}}} +/// `usize` the size of a pointer, index, etc. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"usize-const-definition"}}} +pub const USIZE: Uuid = uuid!["618c6689-4b5e-52a0-88f4-294b825793e6"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Usize; + +impl Usize { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + USIZE + } +} + +impl Default for Usize { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/variable.rs b/src/v2/woog_single/types/variable.rs new file mode 100644 index 00000000..577b53f3 --- /dev/null +++ b/src/v2/woog_single/types/variable.rs @@ -0,0 +1,111 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"variable-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::local::Local; +use crate::v2::woog_single::types::parameter::Parameter; +use crate::v2::woog_single::types::symbol_table::SymbolTable; +use crate::v2::woog_single::types::x_let::XLet; +use crate::v2::woog_single::types::x_value::XValue; +use crate::v2::woog_single::types::x_value::XValueEnum; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-hybrid-documentation"}}} +/// A Variable +/// +/// Basically a name given to some memory. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-hybrid-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct Variable { + pub subtype: VariableEnum, + pub id: Uuid, + pub name: String, + /// R20: [`Variable`] 'exists in a' [`SymbolTable`] + pub symbol_table: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-hybrid-enum-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum VariableEnum { + Local(Uuid), + Parameter(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-implementation"}}} +impl Variable { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-struct-impl-new_local"}}} + /// Inter a new Variable in the store, and return it's `id`. + pub fn new_local( + name: String, + symbol_table: &SymbolTable, + subtype: &Local, + store: &mut WoogSingleStore, + ) -> Variable { + let id = Uuid::new_v4(); + let new = Variable { + name: name, + symbol_table: symbol_table.id, + subtype: VariableEnum::Local(subtype.id), + id, + }; + store.inter_variable(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-struct-impl-new_parameter"}}} + /// Inter a new Variable in the store, and return it's `id`. + pub fn new_parameter( + name: String, + symbol_table: &SymbolTable, + subtype: &Parameter, + store: &mut WoogSingleStore, + ) -> Variable { + let id = Uuid::new_v4(); + let new = Variable { + name: name, + symbol_table: symbol_table.id, + subtype: VariableEnum::Parameter(subtype.id), + id, + }; + store.inter_variable(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-struct-impl-nav-forward-to-symbol_table"}}} + /// Navigate to [`SymbolTable`] across R20(1-*) + pub fn r20_symbol_table<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&SymbolTable> { + vec![store.exhume_symbol_table(&self.symbol_table).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-struct-impl-nav-backward-1_M-to-x_let"}}} + /// Navigate to [`XLet`] across R17(1-M) + pub fn r17_x_let<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&XLet> { + store + .iter_x_let() + .filter(|x_let| x_let.variable == self.id) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"variable-impl-nav-subtype-to-supertype-x_value"}}} + // Navigate to [`XValue`] across R7(isa) + pub fn r7_x_value<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&XValue> { + vec![store + .iter_x_value() + .find(|x_value| { + if let XValueEnum::Variable(id) = x_value.subtype { + id == self.id + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/visibility.rs b/src/v2/woog_single/types/visibility.rs new file mode 100644 index 00000000..a777dfab --- /dev/null +++ b/src/v2/woog_single/types/visibility.rs @@ -0,0 +1,73 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"visibility-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-use-statements"}}} +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +use crate::v2::woog_single::types::access::Access; +use crate::v2::woog_single::types::krate::KRATE; +use crate::v2::woog_single::types::private::PRIVATE; +use crate::v2::woog_single::types::public::PUBLIC; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-enum-documentation"}}} +/// Item Visibility +/// +/// This is a _very_ Rust-centric type. It represents the visibility levels that Rust surfaces +/// . +/// +/// Private is the default, and requires no modifiers. Public is the most open, and indicated +/// by prefixing the item with "pub". In the middle is "pub(crate)", which makes the item public +/// within the crate. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-enum-definition"}}} +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum Visibility { + Krate(Uuid), + Private(Uuid), + Public(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-implementation"}}} +impl Visibility { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-new-impl"}}} + /// Create a new instance of Visibility::Krate + pub fn new_krate() -> Self { + // This is already in the store, see associated function `new` above. + Self::Krate(KRATE) + } + + /// Create a new instance of Visibility::Private + pub fn new_private() -> Self { + // This is already in the store, see associated function `new` above. + Self::Private(PRIVATE) + } + + /// Create a new instance of Visibility::Public + pub fn new_public() -> Self { + // This is already in the store, see associated function `new` above. + Self::Public(PUBLIC) + } + + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-get-id-impl"}}} + pub fn id(&self) -> Uuid { + match self { + Self::Krate(id) => *id, + Self::Private(id) => *id, + Self::Public(id) => *id, + } + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"visibility-struct-impl-nav-backward-1_M-to-access"}}} + /// Navigate to [`Access`] across R14(1-M) + pub fn r14_access<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Access> { + store + .iter_access() + .filter(|access| access.visibility == self.id()) + .collect() + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/woog_option.rs b/src/v2/woog_single/types/woog_option.rs new file mode 100644 index 00000000..8f7dea64 --- /dev/null +++ b/src/v2/woog_single/types/woog_option.rs @@ -0,0 +1,50 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"woog_option-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::grace_type::GraceType; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-struct-documentation"}}} +/// An optional Type +/// +/// In rust this is wrapped in an [`Option`]. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct WoogOption { + pub id: Uuid, + /// R20: [`WoogOption`] 'contains' [`GraceType`] + pub ty: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-implementation"}}} +impl WoogOption { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-struct-impl-new"}}} + /// Inter a new 'Option' in the store, and return it's `id`. + pub fn new(ty: &GraceType, store: &mut WoogSingleStore) -> WoogOption { + let id = Uuid::new_v4(); + let new = WoogOption { id, ty: ty.id() }; + store.inter_woog_option(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-struct-impl-nav-forward-to-ty"}}} + /// Navigate to [`GraceType`] across R20(1-*) + pub fn r20_grace_type<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&GraceType> { + vec![store.exhume_grace_type(&self.ty).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"woog_option-impl-nav-subtype-to-supertype-grace_type"}}} + // Navigate to [`GraceType`] across R2(isa) + pub fn r2_grace_type<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&GraceType> { + vec![store.exhume_grace_type(&self.id).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/x_let.rs b/src/v2/woog_single/types/x_let.rs new file mode 100644 index 00000000..b217f0cf --- /dev/null +++ b/src/v2/woog_single/types/x_let.rs @@ -0,0 +1,83 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"x_let-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::expression::Expression; +use crate::v2::woog_single::types::statement::Statement; +use crate::v2::woog_single::types::statement::StatementEnum; +use crate::v2::woog_single::types::variable::Variable; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-struct-documentation"}}} +/// Let Statement +/// +/// A means of assigning a variable to an expression. I don't think that I'll ever deal with +/// the pattern stuff [a full implementation](https://doc.rust-lang.org/reference/statements.html +/// #let-statements) would require. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct XLet { + pub id: Uuid, + pub x_value: String, + /// R18: [`XLet`] 'to a variable assigns' [`Expression`] + pub expression: Uuid, + /// R17: [`XLet`] 'gives value to a' [`Variable`] + pub variable: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-implementation"}}} +impl XLet { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-struct-impl-new"}}} + /// Inter a new 'Let' in the store, and return it's `id`. + pub fn new( + x_value: String, + expression: &Expression, + variable: &Variable, + store: &mut WoogSingleStore, + ) -> XLet { + let id = Uuid::new_v4(); + let new = XLet { + id, + x_value, + expression: expression.id(), + variable: variable.id, + }; + store.inter_x_let(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-struct-impl-nav-forward-to-expression"}}} + /// Navigate to [`Expression`] across R18(1-*) + pub fn r18_expression<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Expression> { + vec![store.exhume_expression(&self.expression).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-struct-impl-nav-forward-to-variable"}}} + /// Navigate to [`Variable`] across R17(1-*) + pub fn r17_variable<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Variable> { + vec![store.exhume_variable(&self.variable).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_let-impl-nav-subtype-to-supertype-statement"}}} + // Navigate to [`Statement`] across R11(isa) + pub fn r11_statement<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Statement> { + vec![store + .iter_statement() + .find(|statement| { + if let StatementEnum::XLet(id) = statement.subtype { + id == self.id + } else { + false + } + }) + .unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/x_macro.rs b/src/v2/woog_single/types/x_macro.rs new file mode 100644 index 00000000..87f6bad8 --- /dev/null +++ b/src/v2/woog_single/types/x_macro.rs @@ -0,0 +1,36 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"x_macro-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_macro-use-statements"}}} +use serde::{Deserialize, Serialize}; +use uuid::{uuid, Uuid}; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_macro-const-documentation"}}} +/// A Macro Invocation +/// +/// This is here for completeness, and I doubt that I'll ever actually use it. See [the documentation +/// ](https://doc.rust-lang.org/reference/macros.html#macro-invocation). +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_macro-const-definition"}}} +pub const X_MACRO: Uuid = uuid!["bb49a0cc-8490-5129-bec2-d536b43ba6a1"]; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct XMacro; + +impl XMacro { + pub fn new() -> Self { + Self {} + } + + pub fn id(&self) -> Uuid { + X_MACRO + } +} + +impl Default for XMacro { + fn default() -> Self { + Self::new() + } +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}} diff --git a/src/v2/woog_single/types/x_value.rs b/src/v2/woog_single/types/x_value.rs new file mode 100644 index 00000000..9e1d2cc0 --- /dev/null +++ b/src/v2/woog_single/types/x_value.rs @@ -0,0 +1,101 @@ +// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"x_value-struct-definition-file"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-use-statements"}}} +use uuid::Uuid; + +use crate::v2::woog_single::types::access::Access; +use crate::v2::woog_single::types::expression::Expression; +use crate::v2::woog_single::types::grace_type::GraceType; +use crate::v2::woog_single::types::variable::Variable; +use serde::{Deserialize, Serialize}; + +use crate::v2::woog_single::store::ObjectStore as WoogSingleStore; +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-hybrid-documentation"}}} +/// A Value +/// +/// I consider a value as an abstraction for a chunk of memory. By upgrading some bytes to +/// a `Value` you gain meaning and utility. +/// +/// The meaning comes from assigning type information to the ones and zeros. From a modeling +/// perspective it is good enough to think in terms of [`Type`], which is just a general hint +/// about the domain of the value. When we get to generating code we require lower level information +/// , which is why we have [`GraceType`]. +/// +/// The utility are completely compiler/language level constructs. These are [`Mutability`] +/// and [`Visibility`]. +/// +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-hybrid-struct-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub struct XValue { + pub subtype: XValueEnum, + pub id: Uuid, + /// R16: [`XValue`] 'is granted utility by' [`Access`] + pub access: Uuid, + /// R3: [`XValue`] 'is given meaning by a' [`GraceType`] + pub ty: Uuid, +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-hybrid-enum-definition"}}} +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +pub enum XValueEnum { + Expression(Uuid), + Variable(Uuid), +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-implementation"}}} +impl XValue { + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-struct-impl-new_expression"}}} + /// Inter a new XValue in the store, and return it's `id`. + pub fn new_expression( + access: &Access, + ty: &GraceType, + subtype: &Expression, + store: &mut WoogSingleStore, + ) -> XValue { + let id = Uuid::new_v4(); + let new = XValue { + access: access.id, + ty: ty.id(), + subtype: XValueEnum::Expression(subtype.id()), + id, + }; + store.inter_x_value(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-struct-impl-new_variable"}}} + /// Inter a new XValue in the store, and return it's `id`. + pub fn new_variable( + access: &Access, + ty: &GraceType, + subtype: &Variable, + store: &mut WoogSingleStore, + ) -> XValue { + let id = Uuid::new_v4(); + let new = XValue { + access: access.id, + ty: ty.id(), + subtype: XValueEnum::Variable(subtype.id), + id, + }; + store.inter_x_value(new.clone()); + new + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-struct-impl-nav-forward-to-access"}}} + /// Navigate to [`Access`] across R16(1-*) + pub fn r16_access<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&Access> { + vec![store.exhume_access(&self.access).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} + // {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"x_value-struct-impl-nav-forward-to-ty"}}} + /// Navigate to [`GraceType`] across R3(1-*) + pub fn r3_grace_type<'a>(&'a self, store: &'a WoogSingleStore) -> Vec<&GraceType> { + vec![store.exhume_grace_type(&self.ty).unwrap()] + } + // {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +} +// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}} +// {"magic":"","directive":{"End":{"directive":"allow-editing"}}}