Move to crates
This commit is contained in:
parent
ccad41ab9e
commit
11a87bcf5e
8 changed files with 1 additions and 1 deletions
12
crates/vanth/Cargo.toml
Normal file
12
crates/vanth/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "vanth"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
bevy_app.workspace = true
|
||||
bevy_ecs.workspace = true
|
22
crates/vanth/src/lib.rs
Normal file
22
crates/vanth/src/lib.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/// Library crate for the `vanth` ECS-based database node.
|
||||
use bevy_app::App;
|
||||
use bevy_ecs::prelude::*;
|
||||
|
||||
/// A server node wrapping a Bevy App without running it.
|
||||
pub struct Node {
|
||||
app: App,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
/// Creates a new server node with an empty Bevy App.
|
||||
pub fn new() -> Self {
|
||||
let app = App::new();
|
||||
Node { app }
|
||||
}
|
||||
|
||||
/// Returns the number of entities currently in the world.
|
||||
pub fn entity_count(&self) -> usize {
|
||||
// Query for no components returns one item per entity.
|
||||
self.app.world().entities().len()
|
||||
}
|
||||
}
|
9
crates/vanth/src/main.rs
Normal file
9
crates/vanth/src/main.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
#![allow(unused)]
|
||||
|
||||
mod parser;
|
||||
mod util;
|
||||
mod vanth;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
0
crates/vanth/src/parser.rs
Normal file
0
crates/vanth/src/parser.rs
Normal file
60
crates/vanth/src/util.rs
Normal file
60
crates/vanth/src/util.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
/// A 192-bit hash value.
|
||||
pub struct Hash([u8; 24]);
|
||||
|
||||
impl Hash {
|
||||
pub fn from_bytes(value: [u8; 24]) -> Self {
|
||||
Hash(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Hash {
|
||||
/// The Base52 representation of the hash. This will always be 34 ASCII characters long.
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut result = String::with_capacity(34);
|
||||
for chunk in self.0.chunks(4) {
|
||||
let mut value = 0u32;
|
||||
for (i, &byte) in chunk.iter().enumerate() {
|
||||
value |= (byte as u32) << (8 * i);
|
||||
}
|
||||
|
||||
for _ in 0..6 {
|
||||
let digit = value % 52;
|
||||
value /= 52;
|
||||
let c = if digit < 26 {
|
||||
(b'A' + digit as u8) as char
|
||||
} else {
|
||||
(b'a' + (digit - 26) as u8) as char
|
||||
};
|
||||
result.push(c);
|
||||
}
|
||||
}
|
||||
write!(f, "{}", result)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash {
|
||||
pub fn to_string_truncated(&self, length: usize) -> String {
|
||||
self.to_string()[0..length].to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_hash_to_string() {
|
||||
let pairs = [(0u8, "AAAAAA"), (255u8, "ZZZZZZ"), (1u8, "AAAAAB")];
|
||||
let input = [0u8; 24];
|
||||
let hash = Hash::from_bytes(input);
|
||||
let result = hash.to_string();
|
||||
|
||||
assert_eq!(result.len(), 34);
|
||||
|
||||
// String should only contain A-Z and a-z
|
||||
assert!(result.chars().all(|c| c.is_ascii_alphabetic()));
|
||||
|
||||
// With all zero bytes, should start with 'AAAAAA'
|
||||
assert_eq!(&result[0..6], "AAAAAA");
|
||||
}
|
||||
}
|
18
crates/vanth/src/vanth.rs
Normal file
18
crates/vanth/src/vanth.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct Value {}
|
||||
|
||||
pub struct Ty {}
|
||||
|
||||
pub enum Primitive {
|
||||
Bool(bool),
|
||||
Int(i32),
|
||||
Float(f32),
|
||||
String(String),
|
||||
Path(PathBuf),
|
||||
Char(char),
|
||||
Byte(u8),
|
||||
ByteArray(Vec<u8>),
|
||||
}
|
7
crates/vanth/tests/test_node.rs
Normal file
7
crates/vanth/tests/test_node.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use vanth::Node;
|
||||
|
||||
#[test]
|
||||
fn test_entity_count_zero() {
|
||||
let mut node = Node::new();
|
||||
assert_eq!(node.entity_count(), 0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue