rust.code-maven.com
Python has the input function, other languages have a prompt function. This is how we get some input from the user in Rust. There are 3 solutions on this page. The first two are simpler but they would panic! if there is a problem printing t...
Miscellaneous
2024-01-03
~3 min read
rust.code-maven.com
A collection of various web frameworks and other web-related tools in Rust. The ones I have started to review are in bold. Based on the replies to the question I asked on Reddit: Which web framework do you use in Rust? I can say that most o...
Miscellaneous
2023-12-27
~1 min read
rust.code-maven.com
Part of the series about the Rocket web framework. Create crate In order to have a Rocket, we need to create a regular Rust crate. cargo new hello-world cd hello-world Setup dependencies Add rocket = "0.5.0" to the Cargo.toml file: examples...
Miscellaneous
2023-12-27
~2 min read
rust.code-maven.com
Simple example of the max function We start with a simple function that returns the bigger of two values. Basically we are re-implementing the max function as an example. fn main() { let x: i8 = 25; let y: i8 = 42; println!("{}", bigger(x,...
Rust Walkthroughs
2023-12-20
~5 min read
rust.code-maven.com
tiny_http is, well, a tiny crate to create web applications. In this series of articles we are going to see how to use it to build a simple web application. Hello World - set Content-type to text/html. Server, http, incoming_requests, Respo...
Rust Walkthroughs
2023-12-20
~1 min read
rust.code-maven.com
Unlike Python and several other programming languages, Rust does not allow setting default values to function parameters. Luckily with a little bit of macro-writing we can imitate it. Here is the whole example examples/default-arguments/src...
Miscellaneous
2023-12-20
~2 min read
rust.code-maven.com
In some code you will see a construct that looks like this: parse::<i32>() or this collect::<Vec<&str>>() or maybe this: collect::<Vec<_>>() These all use the Turbofish syntax ::<>. When is it used? In some cases Rust can deduce the type of...
Miscellaneous
2023-12-13
~3 min read
rust.code-maven.com
Meetup Stats I wanted to know the relative sizes of the various Rust-specific Meetup groups so I collected them into a YAML file and then generated this page. If you are interested which one is meeting in the next month or so check out This...
Miscellaneous
2023-12-13
~5 min read
rust.code-maven.com
If we don't say what a function returns, it is expected to return (): fn say_hi(name: &str) { println!("Hello {}", name); } However, there are function that never return. For example because they call the panic! macro or the std::process::e...
Miscellaneous
2023-12-06
~3 min read
rust.code-maven.com
Loco is called the one-person framework for Rust for side-projects and startups. I saw it mentioned in on of the local Rust groups, so I thought I would give it a try. I am using loco-cli 0.1.3. By the time you are reading this, there might...
Miscellaneous
2023-12-06
~6 min read
rust.code-maven.com
We already saw how to embed a simple string in our Rust application and also how to use preprocessing to embed a list of values. Now we need to embed a simple CSV file that looks like this: examples/embedded-simple-csv-file/data/languages.c...
Miscellaneous
2023-11-08
~2 min read
rust.code-maven.com
Here is one thing for which I like Rust. Recently, as I wrote some code, I made a typo in a variable name: examples/code_with_typo.rs fn main() { zero(3); zero(0); } fn zero(n: i32) { if i == 0 { println!("zero"); } else { println!("{} is n...
Miscellaneous
2023-08-30
~1 min read
"it's funny, every time I run into a baffling borrow error, it's preventing me from committing a real, serious mistake
but it can take some thinking t..."