From ca95f12c31d2b3b8bfd978c90a2f190c190d0839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Hauspie?= <michael.hauspie@univ-lille.fr> Date: Sun, 31 Mar 2024 15:07:07 +0200 Subject: [PATCH] Move impl block to test (only used in test) --- src/operations.rs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/operations.rs b/src/operations.rs index 383af9d..72e1fd1 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -3,13 +3,12 @@ use serde::{Deserialize, Serialize}; - #[derive(Serialize, Deserialize, Copy, Clone, Debug)] pub enum Operation { - Plus(i32,i32), - Moins(i32,i32), - Fois(i32,i32), - Diviser(i32,i32), + Plus(i32, i32), + Moins(i32, i32), + Fois(i32, i32), + Diviser(i32, i32), } #[derive(Deserialize, Serialize, PartialEq, Debug)] @@ -18,16 +17,6 @@ pub struct OperationResult { resultat: i32, } -impl OperationResult { - /// Creates a new operation result from a [`&str`] and a value. - pub fn new(s: &str, value: i32) -> Self { - Self { - operation: String::from(s), - resultat: value, - } - } -} - impl From<&Operation> for OperationResult { fn from(value: &Operation) -> Self { match value { @@ -57,11 +46,20 @@ impl From<Operation> for OperationResult { } } - #[cfg(test)] mod tests { use super::*; - + + impl OperationResult { + /// Creates a new operation result from a [`&str`] and a value. + pub fn new(s: &str, value: i32) -> Self { + Self { + operation: String::from(s), + resultat: value, + } + } + } + #[test] fn plus() { let operation = Operation::Plus(4, 5); @@ -97,5 +95,4 @@ mod tests { assert_eq!(result, expected); } - } -- GitLab