feat: ✨ talk and listen on client side
This commit is contained in:
parent
1567a9c32a
commit
1e9808579a
11 changed files with 388 additions and 79 deletions
|
@ -1,11 +1,45 @@
|
|||
use std::{collections::VecDeque, fs::File, io::Read};
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
fmt::Display,
|
||||
fs::File,
|
||||
io::Read,
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const BUFFER_LENGTH: usize = 1024;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum Error {
|
||||
ConnectionSetup(String),
|
||||
Connection(String),
|
||||
Send(String),
|
||||
Receive(String),
|
||||
Signal(String),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn cause(&self) -> Option<&dyn std::error::Error> {
|
||||
self.source()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::ConnectionSetup(inner) => write!(f, "Connection Setup | {}", inner),
|
||||
Error::Connection(inner) => write!(f, "Connection | {}", inner),
|
||||
Error::Send(inner) => write!(f, "Send | {}", inner),
|
||||
Error::Receive(inner) => write!(f, "Receive | {}", inner),
|
||||
Error::Signal(inner) => write!(f, "Signal | {}", inner),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct TOML {
|
||||
header: String,
|
||||
fields: VecDeque<String>,
|
||||
fields: HashMap<String, String>,
|
||||
}
|
||||
|
||||
fn naive_toml_parser(file_location: &str) -> TOML {
|
||||
|
@ -21,19 +55,14 @@ fn naive_toml_parser(file_location: &str) -> TOML {
|
|||
.replace(']', "")
|
||||
.trim_end()
|
||||
.to_string();
|
||||
|
||||
let fields = toml_ingredients
|
||||
.iter()
|
||||
.map(|ingredient| {
|
||||
ingredient
|
||||
.split_once('=')
|
||||
.unwrap()
|
||||
.1
|
||||
.replace('"', "")
|
||||
.trim()
|
||||
.to_string()
|
||||
let mut fields = HashMap::new();
|
||||
let _ = toml_ingredients.iter().map(|ingredient| {
|
||||
ingredient.split_once('=').map(|(key, value)| {
|
||||
let key = key.replace('"', "").trim().to_string();
|
||||
let value = value.replace('"', "").trim().to_string();
|
||||
fields.insert(key, value);
|
||||
})
|
||||
.collect();
|
||||
});
|
||||
|
||||
TOML { header, fields }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue