From 8d50d0fd7613ae2a1c42cb307fbc6f7b67f716ce Mon Sep 17 00:00:00 2001 From: rascul Date: Wed, 22 Jun 2022 20:36:45 -0500 Subject: [PATCH] get rid of some fluff --- src/action.rs | 61 ------------------------------------------------ src/form_data.rs | 44 ---------------------------------- src/line.rs | 27 --------------------- src/main.rs | 5 ---- 4 files changed, 137 deletions(-) delete mode 100644 src/action.rs delete mode 100644 src/form_data.rs delete mode 100644 src/line.rs diff --git a/src/action.rs b/src/action.rs deleted file mode 100644 index a3177b6..0000000 --- a/src/action.rs +++ /dev/null @@ -1,61 +0,0 @@ -use lazy_static::lazy_static; -use regex::Regex; - -use crate::Client; - -// this lazy static stuff is so not to recompile the re every time -// unwrap is ok here because compiler will catch it if the string is bad -lazy_static! { - static ref RE: Regex = Regex::new(r"^#!(?P\w+)(?: (?P.*))?$").unwrap(); -} - -/// type of log action -#[derive(Debug)] -pub enum Action { - /// specify client type - Client(Client), - - /// insert a comment in the log - Comment(String), - - /// delay replay - /// duration is number of seconds or 1 if no seconds specified or if duration can't be parsed - Delay(u64), - - /// log line - /// duration is amount of time to sleep before printing the line - Line(String), - - /// insert a marker - Mark, - - /// No match - None, -} - -impl From<&str> for Action { - fn from(line: &str) -> Self { - if line.starts_with("#!") { - let caps = RE.captures(&line).unwrap(); - - let action = if let Some(action) = caps.name("action") { action.as_str() } else { "" }; - - let text = if let Some(text) = caps.name("text") { - text.as_str().to_owned() - } else { - String::new() - }; - - match action { - "client" => Self::Client(Client::from(&text)), - "delay" => Self::Delay(text.parse::().unwrap_or(1)), - "mark" => Self::Mark, - _ => Self::None, - } - } else if line.starts_with("##") { - Self::Comment(line.to_owned()) - } else { - Self::Line(String::new()) - } - } -} diff --git a/src/form_data.rs b/src/form_data.rs deleted file mode 100644 index 246ca22..0000000 --- a/src/form_data.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Data from log submission form - -use std::default::Default; - -use actix_extract_multipart::{File, FileData}; -use serde::Deserialize; - -use crate::Client; - -#[derive(Debug, Deserialize)] -#[serde(default = "FormData::default")] -pub struct FormData { - /// Client - #[serde(rename = "submit_client")] - pub client: Option, - - /// Title - #[serde(rename = "submit_title")] - pub title: Option, - - /// Player - #[serde(rename = "submit_player")] - pub player: Option, - - /// Public - #[serde(rename = "submit_public")] - pub public: Option, - - /// Replay - #[serde(rename = "submit_file")] - pub replay: Option, -} - -impl Default for FormData { - fn default() -> Self { - Self { - client: None, - title: None, - player: None, - public: None, - replay: None, - } - } -} diff --git a/src/line.rs b/src/line.rs deleted file mode 100644 index 61efd13..0000000 --- a/src/line.rs +++ /dev/null @@ -1,27 +0,0 @@ -// use serde::Serialize; - -// #[derive(Debug, Serialize)] -// pub struct Line { -// /// delay before printing the line, in milliseconds -// pub delay: u64, - -// /// text of the line -// pub text: String, -// } - -// impl From<&str> for Line { -// fn from(s: &str) -> Self { -// Self { -// delay: 0, -// text: s.to_owned(), -// } -// } -// } - -pub trait Line { - /// delay before printing the line, in milliseconds - fn delay(&self) -> u64; - - /// text to print - fn text(&self) -> &str; -} diff --git a/src/main.rs b/src/main.rs index cb01925..b2bb7c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,4 @@ -mod action; mod client; -//mod form_data; -mod line; mod options; mod routes; mod wot_log; @@ -12,9 +9,7 @@ use actix_web::{middleware, web, App, HttpServer}; use handlebars::Handlebars; use log::info; -use action::Action; use client::Client; -//use form_data::FormData; use options::Options; use wot_log::WotLog;