hpr3453 :: Rust 101: Episode 1 - Hello, World!
In which BlacKernel introduces the cargo tool and goes into detail on the rust hello world program
Hosted by BlacKernel on Wednesday, 2021-10-27 is flagged as Explicit and is released under a CC-BY-SA license.
rust, programming, hello world, macros, functions.
(Be the first).
The show is available on the Internet Archive at: https://archive.org/details/hpr3453
Listen in ogg,
spx,
or mp3 format. Play now:
Duration: 00:22:28
Programming 101.
A series focusing on concepts and the basics of programming
Talking Points
- main.rs
- Like main.cpp in C++ or main.c in C
- Tells the compiler which file to start with
- Can link to other "crates" and "modules"
- Cargo.toml
- Keeps track of application metadata
- This includes dependencies!
- Functions
- Strictly typed, like everything in Rust
- Declared by
fn
- Argument typed with
argument: Type
- Return typed with
-> Type
otherwise assumed to return nothing
- The Main Function
- Like the main functions in C and C++
- Where the program starts within the main.rs file
- CLI arguments handled by
std::env
, rather thanargv
andargc
in C - Can return nothing or a
Result<()>
- Macros
- Metafunctions or functions for functions
- More general than functions, having flexibility in the number of arguments, etc, but harder to write
- The println! Macro
- Can take any number of arguments that implement the
display
trait - Usually things like strings or character literals
- Will format them into a string and display it on the terminal
- Similar to printf in C
- Can take any number of arguments that implement the
- The Hello World program
- Can be automagically generated with
cargo new
and then the name of your application - Located in
Name-Of-Application/src/main.rs
- Can be automagically generated with
fn main() { println!("Hello, world!"); }
Show Notes
Important Links:
Wikipedia Articles:
Contact Me
- Email: izzyleibowitz at pm dot me
- Mastodon: at blackernel at nixnet dot social