emergency save.

This commit is contained in:
2024-05-05 23:18:42 -04:00
parent 555cf209ba
commit 3955048157
6 changed files with 169 additions and 5 deletions

View File

@ -1,5 +1,9 @@
mod counter;
use rand::distributions::{Alphanumeric, DistString};
use std::{
collections::HashMap,
fmt,
sync::mpsc::{channel, Receiver, Sender},
thread::spawn,
};
@ -25,7 +29,7 @@ enum SendMsg {
}
struct Cache {
data: Vec<String>,
data: HashMap<String, DataType>,
rx: Receiver<SendMsg>,
}
@ -33,7 +37,7 @@ impl Cache {
fn new(recv: Receiver<SendMsg>) -> Self {
Self {
rx: recv,
data: Vec::new(),
data: HashMap::new(),
}
}
@ -53,11 +57,11 @@ impl Cache {
fn validate_session(&mut self, sess: Option<String>) -> Session {
let session: Session;
if sess.is_some_and(|sess| self.data.contains(&sess)) {
if sess.is_some_and(|sess| true) {// self.data.contains(&sess)) {
session = Session::Ok;
} else {
let id = self.gen_id();
self.data.push(id.clone());
// `self.data.push(id.clone());
session = Session::New(id);
}
session
@ -133,3 +137,81 @@ mod client {
}
}
}
enum Field {
StaticString(String),
}
impl fmt::Display for Field {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Field::StaticString(data) => write!(f, "{}", data),
}
}
}
struct Record {
data: HashMap<String, Field>,
}
impl Record {
fn new(data: HashMap<String, Field>) -> Self {
Self {
data: data,
}
}
fn get(&self, fieldname: &str) -> &Field {
match self.data.get(fieldname) {
Some(field) => field,
None => unreachable!(),
}
}
}
#[cfg(test)]
mod records {
use super::*;
#[test]
fn create_record() {
let input = HashMap::from([
("one".to_string(), Field::StaticString("1".to_string())),
("two".to_string(), Field::StaticString("2".to_string())),
("three".to_string(), Field::StaticString("3".to_string())),
]);
let rec = Record::new(input);
assert_eq!(rec.get("one").to_string(), "1");
assert_eq!(rec.get("two").to_string(), "2");
assert_eq!(rec.get("three").to_string(), "3");
}
}
struct Column;
struct Table {
columns: HashMap<String, Column>,
}
impl Table {
fn new() -> Self {
Self {
columns: HashMap::new(),
}
}
}
#[cfg(test)]
mod tables {
use super::*;
#[test]
fn create_table() {
let tbl = Table::new();
}
}
enum DataType {
Table(Table),
Record(Record),
}