Author Archives: Coding Packets Blog
Author Archives: Coding Packets Blog
This post is a collection of links to resources that I have found useful for the Rust programming language. Blogs Books Coding Style Documentation Repositories Video Tutorials Talks drop(_) Learn Rust, it's fn. continue reading
This post is a collection of links to resources that I have found useful for the Rust programming language. Blogs Books Coding Style Documentation Repositories Talks Video Tutorials Written Tutorials drop(_) Learn Rust, it's fn. continue reading
https://codingpackets.com/blog/rust-useful-links
https://codingpackets.com/blog/rust-useful-links
https://codingpackets.com/blog/rust-useful-links
Good Morro Crusty ones 😘. In todays episode of learning Rust, I will show you how to load a TOML file in Rust and additionally handle any possible errors. Software The following software was used in this post. Rust - 1.57.0 toml crate - 0.5.2 serde crate - 1.0.136 ...continue reading
An enum is a type which can be ONE of a FEW different variants. // Create an instance of the enum variants with the double colon. let blah = StuffAndThings::Blah; let bleh = StuffAndThings::Bleh(42); let stuff = StuffAndThings::Stuff(String::from("Stuff"), true); let things =...continue reading
A HashMap is a generic collection of key/value pairs. All of the keys must have the same type, and all of the values must have the same type. HashMap Considerations A hash maps data is stored on the heap. A hash maps size is not known at compile time, they can grow or shrink at run...continue reading
A vector is a collection of items of the same type. Vector Considerations When an empty vector is created with Vec::new it is un-allocated until elements are pushed into it. A vector with elements has allocated memory and lives on the heap. A vector is represented as a pointer to the...continue reading
A trait in Rust is similar to an interface in other languages. Traits define the required behaviour a type MUST implement to satisfy the trait (interface). // Structs that implement the `Greeter` trait. struct Person struct Dog } // Implement the `Greeter` trait for the...continue reading
A struct in Rust is used to encapsulate data. structs can have fields, associated functions and methods. // Instantiate an immutable struct. let sat = StuffAndThings Associated Function Associated functions are tied to an instance of a struct and are usually used as...continue reading
A trait in Rust is similar to an interface in other languages. Traits define the required behaviour a type MUST implement to satisfy the trait (interface). // Structs that implement the `Greeter` trait. struct Person struct Dog } // Implement the `Greeter` trait for the...continue reading
There are two "mainly used" string types in Rust. The str slice, which is mostly seen as a borrowed &str slice. And the errm ... String. Wait ... Wut? String Considerations The data in a borrowed &str slice CANNOT be modified. The data in a String CAN be modified. A &str has a...continue reading
For Loop A for expression extracts values from an iterator until the iterator is empty. for loops in Rust use a similar syntax to Python with the in keyword. } } // => i: blah j: blah' ) }} For Loop Considerations For loops can iterate over anything that implements the...continue reading
An array is a sequence of values, of the same type. A tuple is defined with square brackets []. Array Considerations Arrays live on the stack by default and have a fixed size. Traits are only implemented on an array with a size of 32 or less. Arrays with a size greater than 32 lose...continue reading
A tuple is a sequence of values, which can be of different types. A tuple is defined with circle brackets (). Tuple Considerations The number of elements in a tuple is known as its arity. Traits are only implemented on a tuple with an arity of 12 or less. Tuples with an arity...continue reading
A char in Rust represents a single unicode scalar value. A char is defined as a single character within single quotes eg: ('a'). Char Considerations A char is not the same as a single str character. Strings DO NOT use chars internally. A char is always 4-bytes in length. continue reading
The if conditional block in Rust behaves similarly to other languages. In Rust, if blocks act as an expression and the resulting branch can be assigned to a variable. The resulting expression of an if branch can be assigned to a variable with the let keyword. If...continue reading
The boolean type in Rust is defined with the bool type annotation and can be either a true or false literal. Boolean Considerations false has a bit battern of 0x00 true has a bit battern of 0x01 Booleans cannot be used in arithmatic unless they are cast to a u8 continue reading
Integers Integers represent whole numbers. Rust has both unsigned integers and signed integers. unsigned integers cannot be negative, and have a higher positive range than signed integers, that can be negative, but have a lower postive range. The following table lists the integer...continue reading