You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.5 KiB

//! Server state
use super::*;
use std::{
collections::HashMap,
};
use generational_arena::{
Arena, Index,
};
/// Possible value types of the data map
#[derive(Debug, Serialize, Deserialize)]
pub enum Data
{
Byte(u8),
Char(char),
Bool(bool),
SI(i64),
UI(u64),
FI(f64),
Text(String),
Binary(Vec<u8>),
/// A reference index to an item within the same `Datamap` as this one.
RelativeRef(Index),
/// A reference to an item N deep within nested `Map` elements.
///
/// The first `Index` specifies the `Map` data item at the root `Datamap` that contains the next, et cetera. The pointed to value is the last index.
AbsoluteRef(Vec<Index>),
List(Vec<Atom>),
Map(Datamap),
Null,
}
/// Information about a map entry.
#[derive(Debug, Serialize, Deserialize)]
pub struct Info
{
created: u64,
modified: u64,
//TODO: Info about who owns it, perms, etc.
}
/// The root data containing map
#[derive(Debug, Serialize, Deserialize)]
pub struct Datamap
{
data: Arena<Atom>,
ident: HashMap<Identifier, Index>,
}
/// A value in a datamap, contains the information about the value and the value itself.
#[derive(Debug, Serialize, Deserialize)]
pub struct Atom(Data, Info);
/// An identifier for an item in a `Datamap`, or an item nested within many `Datamap`s.
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Identifier(String);
/// Contains the state of the whole program
#[derive(Debug)]
pub struct ServerState
{
root: Datamap,
}