priprava 4

This commit is contained in:
Priec
2026-02-21 18:52:22 +01:00
parent 4b452112e9
commit d26cd97aa9
4 changed files with 1108 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
pub mod priprava3;
use serde::Deserialize;
use serde::Serialize;
use std::fmt;

View File

@@ -1,4 +1,7 @@
use JR_priprava_na_skusku6::priprava3;
fn main() {
priprava3::spusti();
match std::fs::read_to_string("subor.txt") {
Ok(x) => print!("{x}"),
Err(y) => print!("{y}"),
@@ -56,3 +59,6 @@ fn nacitaj_json(cesta: &str) -> Option<Vec<String>> {
let vec = serde_json::from_str::<Vec<String>>(nacitane.as_str());
Some(vec.ok()?)
}

View File

@@ -0,0 +1,35 @@
use std::fmt;
use std::collections::HashMap;
pub fn spusti() {
let mut mapa: HashMap<String, i32> = HashMap::new();
// Vloženie
mapa.insert("Anna".to_string(), 25);
mapa.insert("Boris".to_string(), 30);
// Čítanie — vráti Option<&V>
let vek: Option<&i32> = mapa.get("Anna"); // Some(&25)
let vek: Option<&i32> = mapa.get("Cyril"); // None
// Kontrola existencie
let existuje: bool = mapa.contains_key("Anna"); // true
// Iterácia
for (meno, vek) in &mapa {
println!("{}: {}", meno, vek);
}
}
struct Kniha { nazov: String, rok: u16 }
impl fmt::Display for Kniha {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.nazov, self.rok)
}
}
#[derive(Debug)]
struct Zamestnanec { plat: u32 }
struct Student { meno: String, vek: u8, priemer: f32 }