From 36347d16615a1569fe5dbf26ae8726fc1caa8afa Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Mon, 22 Jul 2024 14:54:22 +0200 Subject: [PATCH] refactor(evaluation): move evaluation to a new module --- src/game/evaluation.rs | 33 +++++++++++++++++++++++++++++++++ src/game/mod.rs | 3 +++ 2 files changed, 36 insertions(+) create mode 100644 src/game/evaluation.rs diff --git a/src/game/evaluation.rs b/src/game/evaluation.rs new file mode 100644 index 0000000..d99cb4d --- /dev/null +++ b/src/game/evaluation.rs @@ -0,0 +1,33 @@ +use std::convert::Infallible; +use std::str::FromStr; + +use super::response::Status; + +#[derive(Debug, Clone, PartialEq, Default)] +pub struct Evaluation { + inner: Vec, +} +pub type EvaluationUnit = (char, Status); + +impl IntoIterator for Evaluation { + type Item = EvaluationUnit; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.inner.into_iter() + } +} + +impl From> for Evaluation { + fn from(value: Vec) -> Self { + Self { inner: value } + } +} + +impl FromStr for Evaluation { + type Err = Infallible; + fn from_str(s: &str) -> Result { + // TODO: make this proper + Ok(vec![('x', Status::None)].into()) + } +} diff --git a/src/game/mod.rs b/src/game/mod.rs index 8ce9996..a1f36d4 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -9,6 +9,9 @@ use libpt::log::{debug, trace}; pub mod response; use response::GuessResponse; +pub mod evaluation; +use evaluation::*; + pub mod summary; use self::response::{Evaluation, Status};