This commit is contained in:
Priec
2026-02-15 23:56:52 +01:00
parent f8814e7e1a
commit 7fe89b0361
2 changed files with 97 additions and 1 deletions

View File

@@ -78,6 +78,30 @@ impl Filmoteka {
result
}
fn nacitaj(cesta: &str) -> Result<String, std::io::Error> {
std::fs::read_to_string(cesta)
}
fn nacitaj2(cesta: &str) -> bool {
std::fs::read_to_string(cesta).is_ok()
}
fn nacitaj3(cesta: &str) -> Result<String, String> {
match std::fs::read_to_string(cesta) {
Ok(obsah) => Ok(obsah),
Err(err) => Err(err.to_string()),
}
}
fn parsuj_cislo(text: &str) -> Option<i32> {
let x = text.parse::<i32>();
x.ok()
}
fn parsuj_cislo2(text: &str) -> Option<i32> {
text.parse::<i32>().ok()
}
pub fn uloz_do_suboru(&self, cesta: &std::path::PathBuf) -> bool {
let Ok(json) = serde_json::to_string_pretty(&self) else {
return false;
@@ -86,3 +110,22 @@ impl Filmoteka {
}
}
impl Film {
pub fn new(
nazov: &str,
reziser: &str,
rok: u16,
zaner: Zaner,
hodnotenie: f32
) -> Option<Self> {
if hodnotenie < 0.0 || hodnotenie > 10.0 {
return None;
};
return Some(Self {
nazov: nazov.to_string(),
reziser: reziser.to_string(),
rok, zaner, hodnotenie
})
}
}