diff --git a/crates/vanth/src/hashing_serializer.rs b/crates/vanth/src/hashing_serializer.rs index 982190e..0a4d1eb 100644 --- a/crates/vanth/src/hashing_serializer.rs +++ b/crates/vanth/src/hashing_serializer.rs @@ -11,8 +11,11 @@ use serde::{ }, }; -use crate::ContentHash; +use crate::{ContentHash, Ty}; +/// Returns the [`ContentHash`] of any type implementing [`Serialize`]. +/// +/// The type name itself is not included in the hash, and so two values with different types may produce the same hash. /// Use a combination of [`Ty`] and [`ContentHash`] to uniquely identify values. pub fn hash(value: &impl Serialize) -> ContentHash { let mut digest = blake3::Hasher::new(); let mut serializer = HashingSerializer { digest: &mut digest }; diff --git a/crates/vanth/src/lib.rs b/crates/vanth/src/lib.rs index 3324fee..ab37350 100644 --- a/crates/vanth/src/lib.rs +++ b/crates/vanth/src/lib.rs @@ -1,5 +1,3 @@ -#![doc = include_str!("../../../README.md")] - use std::marker::PhantomData; use bevy_ecs::{prelude::*, query::QueryData}; @@ -9,6 +7,7 @@ use crate::entity::EntityId; pub mod entity; pub mod hashing_serializer; +pub mod nix; pub mod store; pub use hashing_serializer::hash; @@ -20,14 +19,20 @@ pub enum Error { Other(String), } + +/// A view of all of the [`Node`]s in a cluster. +pub struct Network { + // TODO +} + /// A Vanth server. pub struct Node { - + // TODO } impl Node { pub fn new() -> Self { - Self { } + Self {} } pub fn entity_count(&self) -> usize { @@ -70,6 +75,8 @@ pub struct Value { data: Vec, } +/// A wrapper for the fully-qualified name of a Rust type. This should be univerisally unique for a given type within a +/// given project. #[derive(Clone, Debug, Deserialize, Serialize, Eq, Hash)] pub struct Ty { pub path: Vec, @@ -93,10 +100,19 @@ impl> PartialEq for Ty { } } +/// All types stored in the Vanth database should implement this trait. pub trait Vanth { + /// Get the [`Ty`] representing this type. fn ty() -> Ty; } +macro_rules! impl_vanth { + // TODO + () => {}; +} + +// impl_vanth!(std::string::String) + // TODO: Impl for different tuple sizes pub trait VanthTuple {} @@ -112,12 +128,11 @@ pub struct ComponentContents { _marker: PhantomData, } -pub trait Component: Serialize { - fn id() -> String; -} - // use a macro to implement VanthTuiple here. +/// A 32 byte BLAKE3 hash representing the contents of some value. +/// +/// This can be generated with the [`hash`] function. #[derive(Copy, Clone, Debug, Deserialize, Component, Serialize, PartialEq, Eq, Hash)] pub struct ContentHash { pub hash: [u8; 32], @@ -167,10 +182,5 @@ pub struct Handle { _marker: PhantomData, } - -// fn run_reference_tasks(tasks: Query<(&ReferenceGetTask<>)>) { - -// } - /// A world which Vanth entities live in. Lifetimes `'v` of [`Vanth<'v>`] types are tied to the lifetime of the `Root`. pub struct Root {} diff --git a/crates/vanth/src/nix.rs b/crates/vanth/src/nix.rs new file mode 100644 index 0000000..a17f9d7 --- /dev/null +++ b/crates/vanth/src/nix.rs @@ -0,0 +1,7 @@ +pub struct NixosModule { + +} + +pub struct NixExpression { + +} diff --git a/crates/vanth/tests/integration/main.rs b/crates/vanth/tests/integration/main.rs index 74fc9a6..9204b6f 100644 --- a/crates/vanth/tests/integration/main.rs +++ b/crates/vanth/tests/integration/main.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use vanth::{Component, Node, Reference}; +use vanth::{Node, Reference}; mod derive; mod fs;