34 lines
734 B
Rust
34 lines
734 B
Rust
use std::fs;
|
|
|
|
pub mod diagnostics;
|
|
|
|
pub fn char_to_u64(s : char) -> Option<u64> {
|
|
s.to_string().parse::<u64>().ok()
|
|
}
|
|
|
|
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_i32(s : &str) -> Option<i32> {
|
|
s.trim().to_string().parse::<i32>().ok()
|
|
}
|
|
|
|
pub fn str_to_u8(s : &str) -> Option<u8> {
|
|
s.trim().to_string().parse::<u8>().ok()
|
|
}
|
|
|
|
pub fn str_to_u32(s : &str) -> Option<u32> {
|
|
s.trim().to_string().parse::<u32>().ok()
|
|
}
|
|
|
|
pub fn str_to_u64(s : &str) -> Option<u64> {
|
|
s.trim().to_string().parse::<u64>().ok()
|
|
}
|