✨📝💩 vanth: Add nix
module and improve documentation
- Added new module `nix` containing `NixosModule` and `NixExpression` structs. - Added documentation comments for the `hash` function regarding type exclusion in output. - Added documentation for `Network`, `ContentHash`, `Ty`, and `Vanth` trait. - Added TODO stubs for `Network` implementation and `impl_vanth` macro. - Removed the `Component` trait and updated `Node` struct to have empty braces. - Removed unused `Component` import from integration tests.
This commit is contained in:
parent
b927702ee2
commit
6f88a09b09
4 changed files with 35 additions and 15 deletions
|
@ -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 };
|
||||
|
|
|
@ -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<u8>,
|
||||
}
|
||||
|
||||
/// 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<String>,
|
||||
|
@ -93,10 +100,19 @@ impl<T: AsRef<str>> PartialEq<T> 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<T: Vanth> {
|
|||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
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<T> {
|
|||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
|
||||
// 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 {}
|
||||
|
|
7
crates/vanth/src/nix.rs
Normal file
7
crates/vanth/src/nix.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub struct NixosModule {
|
||||
|
||||
}
|
||||
|
||||
pub struct NixExpression {
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use vanth::{Component, Node, Reference};
|
||||
use vanth::{Node, Reference};
|
||||
|
||||
mod derive;
|
||||
mod fs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue