Add comments to help explain Graphene concepts

This commit is contained in:
Keavon Chambers
2023-10-24 21:32:42 -07:00
parent ee08938bb0
commit bafde43145
5 changed files with 78 additions and 45 deletions

View File

@@ -2,6 +2,25 @@ use core::marker::PhantomData;
use crate::{Node, NodeMut};
// This is how we can generically define composition of two nodes.
// This is done generically as shown: <https://files.keavon.com/-/SurprisedGaseousAnhinga/capture.png>
// A concrete example: <https://files.keavon.com/-/ExcitableGoldRay/capture.png>
// And showing the direction of data flow: <https://files.keavon.com/-/SoreShimmeringElephantseal/capture.png>
/// ┌────────────────┐
/// T │ │ U
/// ───────────►│ Compose Node ├───────────►
/// │ │
/// └────┬───────────┤
/// ┌──────────┐ │ │
/// │ │ T -> V │ │
/// │ First ├─────────────►│ │
/// │ │ │ │
/// └──────────┘ │ │
/// ┌──────────┐ │ │
/// │ │ V -> U │ │
/// │ Second ├─────────────►│ │
/// │ │ └───────────┘
/// └──────────┘
#[derive(Clone, Copy)]
pub struct ComposeNode<First, Second, I> {
first: First,

View File

@@ -102,12 +102,18 @@ impl PartialEq for TypeDescriptor {
}
}
/// Graph runtime type information used for type inference.
#[derive(Clone, PartialEq, Eq, Hash, specta::Type)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Type {
/// A wrapper for some type variable used within the inference system. Resolved at inference time and replaced with a concrete type.
Generic(Cow<'static, str>),
/// A wrapper around the Rust type id for any concrete Rust type. Allows us to do equality comparisons, like checking if a String == a String.
Concrete(TypeDescriptor),
/// Runtime type information for a function. Given some input, gives some output.
/// See the example and explanation in the `ComposeNode` implementation within the node registry for more info.
Fn(Box<Type>, Box<Type>),
/// Not used at the moment.
Future(Box<Type>),
}