parent
e120cd547d
commit
ca989eb51d
@ -1,8 +1,69 @@
|
||||
//! Server state
|
||||
use super::*;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
};
|
||||
use generational_arena::{
|
||||
Arena, Index,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServerState
|
||||
/// 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,
|
||||
}
|
||||
|
Loading…
Reference in new issue