Skip to content
Snippets Groups Projects
Commit c6f4dbaa authored by nutzer05's avatar nutzer05
Browse files

Add docs to lib

parent d3fa2e3c
No related branches found
No related tags found
No related merge requests found
...@@ -2,27 +2,42 @@ use log::debug; ...@@ -2,27 +2,42 @@ use log::debug;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// All available operations of the calculator API
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
enum CalcOp { enum CalcOp {
/// Add two numbers
Add, Add,
/// Substract two numbers
Sub, Sub,
/// Multiply two numbers
Mul, Mul,
/// Divide two numbers
Div, Div,
} }
/// A request to the calculator API
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct CalcReq { pub struct CalcReq {
/// Left-hand operand of the calculation
a: i32, a: i32,
/// Right-hand operand of the calculation
b: i32, b: i32,
/// The operation to calculate
op: CalcOp, op: CalcOp,
} }
/// Result of a calculation of the calculator API
#[derive(Serialize)] #[derive(Serialize)]
pub struct CalcRes { pub struct CalcRes {
/// Result of the calculation
res: i32, res: i32,
} }
impl CalcReq { impl CalcReq {
/// Perform the calculation
///
/// Returns a [CalcRes] in case the calculation was successful, or
/// an error if it overflows or causes other arithmetic errors.
pub fn calc(&self) -> Option<CalcRes> { pub fn calc(&self) -> Option<CalcRes> {
debug!("Calculating: {:?}", self); debug!("Calculating: {:?}", self);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment