use std::fs; pub mod diagnostics; pub fn char_to_u8(c : char) -> Option { char_to_u32(c).and_then(|n| u8::try_from(n).ok()) } pub fn char_to_u32(c : char) -> Option { c.to_digit(10) } pub fn char_to_u64(c : char) -> Option { char_to_u32(c).map(u64::from) } pub fn read_from_file(name : &str) -> String { match fs::read_to_string(name) { Err(error) => { println!("Failed to read file {name}: {error}"); String::new() }, Ok(s) => s, } } pub fn str_to_i16(s : &str) -> Option { s.trim().to_string().parse::().ok() } // pub fn str_to_i32(s : &str) -> Option { // s.trim().to_string().parse::().ok() // } // pub fn str_to_u8(s : &str) -> Option { // s.trim().to_string().parse::().ok() // } // pub fn str_to_u16(s : &str) -> Option { // s.trim().to_string().parse::().ok() // } // pub fn str_to_u32(s : &str) -> Option { // s.trim().to_string().parse::().ok() // } pub fn str_to_u64(s : &str) -> Option { s.trim().to_string().parse::().ok() } pub fn str_to_u128(s : &str) -> Option { s.trim().to_string().parse::().ok() }