simple program in Rust has compilation errors

Advertisements I’m new to Rust and I’m trying to write down a simple example using loops the code is the following: fn main() { let exit: u8 = loop_break(20, 5); println!("loop_break exited with value {exit}"); let exit: u8 = loop_break(20, 35); println!("loop_break exited with value {exit}"); let exit: u8 = loop_break(20, 20); println!("loop_break exited with… Read More simple program in Rust has compilation errors

how to fix error in trie implementation in rust?

Advertisements I’m trying to implement a trie in rust to learn the language, especially around recursive structures. In the process, I"m seeing that the add_word method gives me an error. The implementation is use std::array; #[derive(Default)] pub struct Trie { is_end: bool, pub children: [Option<Box<Trie>>; 26], } impl Trie { pub fn new() -> Box<Self>… Read More how to fix error in trie implementation in rust?

Rust function returning std::time::Instant

Advertisements I have a function that returns time elapsed. I had originally tried fn insert_test(Table: &mut HashMap<String,String>, items: &Vec<String>) -> std::time::Instant { But the compiler errored on ^^^^^^^^ expected struct `Instant`, found `u128` But the compiler tells me to use u128 instead But how would I know u128 ahead of time? https://doc.rust-lang.org/std/time/struct.Instant.html itself does not… Read More Rust function returning std::time::Instant