feat(rep): 1 lab

This commit is contained in:
Black_Raven committed 2025-12-04 14:27:08 +03:00
1 parent 76012111bc
commit ee49a6936e
4 files changed
+72

No files matched your search

Generated
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "Learning"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "Learning"
version = "0.1.0"
edition = "2024"
[dependencies]
+11
View File
@@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cargo
rustc
rustfmt
clippy
rust-analyzer
];
}
+48
View File
@@ -0,0 +1,48 @@
enum MATH {
ADD,
SUB,
MUL,
DEV,
}
struct Math {
a: i32,
b: i32,
}
impl Math {
fn init(a: i32, b: i32) -> Math {
return Math { a, b };
}
fn calculate(&self, operation: MATH) -> i32 {
match operation {
MATH::ADD => return self.a + self.b,
MATH::SUB => return self.a - self.b,
MATH::MUL => return self.a * self.b,
MATH::DEV => {
if self.b == 0 {
return 0;
} else {
return self.a / self.b;
}
}
}
}
fn reinit(&mut self, a: i32, b: i32) {
self.a = a;
self.b = b;
}
}
fn main() {
let operation: MATH = MATH::ADD;
let mut calculator: Math = Math::init(10, 4);
print!("ans: {}\n", calculator.calculate(operation));
calculator.reinit(32, 2);
println!("ans after reinit: {}", calculator.calculate(MATH::DEV));
}