2024-02-10 17:52:19 +00:00
# Rust QaStaHvIS
2022-06-26 16:12:47 +00:00
2024-02-10 17:52:19 +00:00
### QaStaHvIS QaD
2022-06-26 16:12:47 +00:00
2024-02-10 17:52:19 +00:00
QaStaHvIS vItlhutlh 1 vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vIt
2022-06-26 16:12:47 +00:00
```rust
struct Wrapper< T > {
2024-02-10 17:52:19 +00:00
value: T,
2022-06-26 16:12:47 +00:00
}
impl< T > Wrapper< T > {
2024-02-10 17:52:19 +00:00
pub fn new(value: T) -> Self {
Wrapper { value }
}
2022-06-26 16:12:47 +00:00
}
Wrapper::new(42).value
Wrapper::new("Foo").value, "Foo"
```
### Option, Some & None
2024-02-10 17:52:19 +00:00
**Option** lo' means that the value might by of type **Some** (ghaH) or **None** (pagh):
2022-06-26 16:12:47 +00:00
```rust
pub enum Option< T > {
2024-02-10 17:52:19 +00:00
None,
Some(T),
2022-06-26 16:12:47 +00:00
}
```
2022-06-27 08:23:29 +00:00
### Macros
Macros are more powerful than functions because they expand to produce more code than the code you’ ve written manually. For example, a function signature must declare the number and type of parameters the function has. Macros, on the other hand, can take a variable number of parameters: we can call `println!("hello")` with one argument or `println!("hello {}", name)` with two arguments. Also, macros are expanded before the compiler interprets the meaning of the code, so a macro can, for example, implement a trait on a given type. A function can’ t, because it gets called at runtime and a trait needs to be implemented at compile time.
```rust
macro_rules! my_macro {
2024-02-10 17:52:19 +00:00
() => {
println!("Check out my macro!");
};
($val:expr) => {
println!("Look at this other macro: {}", $val);
}
2022-06-27 08:23:29 +00:00
}
fn main() {
2024-02-10 17:52:19 +00:00
my_macro!();
my_macro!(7777);
2022-06-27 08:23:29 +00:00
}
// Export a macro from a module
mod macros {
2024-02-10 17:52:19 +00:00
#[macro_export]
macro_rules! my_macro {
() => {
println!("Check out my macro!");
};
}
2022-06-27 08:23:29 +00:00
}
```
2024-02-10 17:52:19 +00:00
### Qap
2022-06-27 08:23:29 +00:00
2024-02-10 17:52:19 +00:00
{::comment}
2022-06-27 08:23:29 +00:00
### Iterate
2024-02-10 17:52:19 +00:00
{:/comment}
{::comment}
#### Rust
{:/comment}
In Rust, you can use the `iter` method to iterate over a collection. The `iter` method returns an iterator, which allows you to loop over the elements of the collection.
Here's an example of how to use the `iter` method:
```rust
let numbers = vec![1, 2, 3, 4, 5];
for number in numbers.iter() {
println!("Number: {}", number);
}
```
This code will iterate over the `numbers` vector and print each number.
2022-06-27 08:23:29 +00:00
2024-02-10 17:52:19 +00:00
{::comment}
#### Klingon
{:/comment}
Rust vItlhutlh, vaj vItlhutlhDaq 'iter' method vay' vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq vItlhutlhDaq
2022-06-27 08:23:29 +00:00
```rust
// Iterate through a vector
let my_fav_fruits = vec!["banana", "raspberry"];
let mut my_iterable_fav_fruits = my_fav_fruits.iter();
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
assert_eq!(my_iterable_fav_fruits.next(), None); // When it's over, it's none
2024-02-10 17:52:19 +00:00
2022-06-27 08:23:29 +00:00
// One line iteration with action
my_fav_fruits.iter().map(|x| capitalize_first(x)).collect()
// Hashmap iteration
for (key, hashvalue) in & *map {
for key in map.keys() {
for value in map.values() {
```
2024-02-10 17:52:19 +00:00
### Qa'Hom Qa'Hom
#### Description
A recursive box is a data structure in Rust that allows for the creation of self-referential data. It is commonly used when dealing with data that needs to have a reference to itself.
#### Syntax
To create a recursive box in Rust, you can use the `Box` type along with the `Rc` (Reference Counted) or `Arc` (Atomic Reference Counted) smart pointers.
```rust
use std::rc::Rc;
use std::sync::Arc;
struct Node {
value: i32,
next: Option< Box < Node > >,
}
fn main() {
// Using Rc
let node1 = Rc::new(Node {
value: 1,
next: None,
});
let node2 = Rc::new(Node {
value: 2,
next: Some(Box::new(node1.clone())),
});
node1.next = Some(Box::new(node2.clone()));
// Using Arc
let node3 = Arc::new(Node {
value: 3,
next: None,
});
let node4 = Arc::new(Node {
value: 4,
next: Some(Box::new(node3.clone())),
});
node3.next = Some(Box::new(node4.clone()));
}
```
#### Explanation
In the example above, we define a `Node` struct that contains a value of type `i32` and an optional `next` field of type `Option<Box<Node>>` . This allows each `Node` to have a reference to another `Node` .
We then create instances of `Node` using either `Rc` or `Arc` smart pointers. With `Rc` , the reference count is incremented each time a new reference is created, while with `Arc` , atomic operations are used to ensure thread safety.
In the `main` function, we create a chain of nodes by setting the `next` field of each node to a `Some` variant containing a boxed reference to the next node. This creates a self-referential data structure.
2022-06-27 08:23:29 +00:00
2024-02-10 17:52:19 +00:00
#### Advantages
2022-06-27 08:23:29 +00:00
2024-02-10 17:52:19 +00:00
- Allows for the creation of self-referential data structures.
- Provides memory safety by automatically managing the lifetime of references.
- Supports both single-threaded (`Rc`) and multi-threaded (`Arc`) scenarios.
#### Disadvantages
- Can introduce overhead due to reference counting or atomic operations.
- May require additional care to avoid reference cycles and memory leaks.
#### Example Use Cases
- Linked lists
- Trees
- Graphs
2022-06-27 08:23:29 +00:00
```rust
enum List {
2024-02-10 17:52:19 +00:00
Cons(i32, List),
Nil,
2022-06-27 08:23:29 +00:00
}
let list = Cons(1, Cons(2, Cons(3, Nil)));
```
2022-06-26 16:12:47 +00:00
### Conditionals
#### if
2024-02-10 17:52:19 +00:00
##### if
2022-06-26 16:12:47 +00:00
```rust
let n = 5;
if n < 0 {
2024-02-10 17:52:19 +00:00
print!("{} is negative", n);
2022-06-26 16:12:47 +00:00
} else if n > 0 {
2024-02-10 17:52:19 +00:00
print!("{} is positive", n);
2022-06-26 16:12:47 +00:00
} else {
2024-02-10 17:52:19 +00:00
print!("{} is zero", n);
2022-06-26 16:12:47 +00:00
}
```
2024-02-10 17:52:19 +00:00
#### tlhIngan Hol
2022-06-26 16:12:47 +00:00
#### match
2024-02-10 17:52:19 +00:00
`match` jatlhlaHbe'chugh, 'ej 'oHbejbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, 'ej vItlhutlhbe'chugh, '
2022-06-26 16:12:47 +00:00
```rust
match number {
2024-02-10 17:52:19 +00:00
// Match a single value
1 => println!("One!"),
// Match several values
2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
// TODO ^ Try adding 13 to the list of prime values
// Match an inclusive range
13..=19 => println!("A teen"),
// Handle the rest of cases
_ => println!("Ain't special"),
2022-06-26 16:12:47 +00:00
}
let boolean = true;
// Match is an expression too
let binary = match boolean {
2024-02-10 17:52:19 +00:00
// The arms of a match must cover all the possible values
false => 0,
true => 1,
// TODO ^ Try commenting out one of these arms
2022-06-26 16:12:47 +00:00
};
```
#### loop (infinite)
2024-02-10 17:52:19 +00:00
##### loop (vItlhutlh)
2022-06-26 16:12:47 +00:00
```rust
loop {
2024-02-10 17:52:19 +00:00
// code to be executed repeatedly
2022-06-26 16:12:47 +00:00
}
```
2024-02-10 17:52:19 +00:00
The `loop` keyword in Rust is used to create an infinite loop. The code inside the loop will be executed repeatedly until the loop is explicitly terminated using a `break` statement or an error occurs. This construct is useful when you want to continuously perform a certain task or wait for a specific condition to be met.
```rust
loop {
count += 1;
if count == 3 {
println!("three");
continue;
}
println!("{}", count);
if count == 5 {
println!("OK, that's enough");
break;
}
}
```
2022-06-26 16:12:47 +00:00
#### while
2024-02-10 17:52:19 +00:00
##### tlhIngan Hol
#### while
##### tlhIngan Hol
2022-06-26 16:12:47 +00:00
```rust
let mut n = 1;
while n < 101 {
2024-02-10 17:52:19 +00:00
if n % 15 == 0 {
println!("fizzbuzz");
} else if n % 5 == 0 {
println!("buzz");
} else {
println!("{}", n);
}
n += 1;
2022-06-26 16:12:47 +00:00
}
```
#### for
2024-02-10 17:52:19 +00:00
#### for
2022-06-26 16:12:47 +00:00
```rust
for n in 1..101 {
2024-02-10 17:52:19 +00:00
if n % 15 == 0 {
println!("fizzbuzz");
} else {
println!("{}", n);
}
2022-06-26 16:12:47 +00:00
}
// Use "..=" to make inclusive both ends
for n in 1..=100 {
2024-02-10 17:52:19 +00:00
if n % 15 == 0 {
println!("fizzbuzz");
} else if n % 3 == 0 {
println!("fizz");
} else if n % 5 == 0 {
println!("buzz");
} else {
println!("{}", n);
}
2022-06-26 16:12:47 +00:00
}
// ITERATIONS
let names = vec!["Bob", "Frank", "Ferris"];
//iter - Doesn't consume the collection
for name in names.iter() {
2024-02-10 17:52:19 +00:00
match name {
& "Ferris" => println!("There is a rustacean among us!"),
_ => println!("Hello {}", name),
}
2022-06-26 16:12:47 +00:00
}
//into_iter - COnsumes the collection
for name in names.into_iter() {
2024-02-10 17:52:19 +00:00
match name {
"Ferris" => println!("There is a rustacean among us!"),
_ => println!("Hello {}", name),
}
2022-06-26 16:12:47 +00:00
}
//iter_mut - This mutably borrows each element of the collection
for name in names.iter_mut() {
2024-02-10 17:52:19 +00:00
*name = match name {
& mut "Ferris" => "There is a rustacean among us!",
_ => "Hello",
}
2022-06-26 16:12:47 +00:00
}
```
2024-02-10 17:52:19 +00:00
#### 'ej vaj
`if let` is a shorthand syntax in Rust that combines an `if` statement with a `let` statement. It allows you to conditionally match and destructure an enum variant or pattern match a value, and bind the matched value to a variable if the condition is true.
2022-06-26 16:12:47 +00:00
2024-02-10 17:52:19 +00:00
Here's the basic syntax:
2022-06-26 16:12:47 +00:00
2024-02-10 17:52:19 +00:00
```rust
if let Some(value) = optional_value {
// Code to execute if optional_value is Some
} else {
// Code to execute if optional_value is None
}
```
In Klingon:
```klingon
'ej vaj Some(value) = optional_value {
// optional_value vaj Some boq 'e' vItlhutlh
} else {
// optional_value vaj None boq 'e' vItlhutlh
}
```
The `if let` statement can be used with various patterns, including tuples, structs, and enums. It provides a concise way to handle specific cases without the need for nested `match` statements or multiple `if` conditions.
2022-06-26 16:12:47 +00:00
```rust
let optional_word = Some(String::from("rustlings"));
if let word = optional_word {
2024-02-10 17:52:19 +00:00
println!("The word is: {}", word);
2022-06-26 16:12:47 +00:00
} else {
2024-02-10 17:52:19 +00:00
println!("The optional word doesn't contain anything");
2022-06-26 16:12:47 +00:00
}
```
2024-02-10 17:52:19 +00:00
#### while let
##### tlhIngan Hol
2022-06-26 16:12:47 +00:00
#### while let
2024-02-10 17:52:19 +00:00
##### tlhIngan Hol
2022-06-26 16:12:47 +00:00
```rust
let mut optional = Some(0);
// This reads: "while `let` destructures `optional` into
// `Some(i)` , evaluate the block (`{}`). Else `break` .
while let Some(i) = optional {
2024-02-10 17:52:19 +00:00
if i > 9 {
println!("Greater than 9, quit!");
optional = None;
} else {
println!("`i` is `{:?}` . Try again.", i);
optional = Some(i + 1);
}
// ^ Less rightward drift and doesn't require
// explicitly handling the failing case.
2022-06-26 16:12:47 +00:00
}
```
### Traits
Create a new method for a type
2024-02-10 17:52:19 +00:00
#### tlhIngan Hol Translation:
### cha'logh
nIvbogh lo'laHbe'ghach vItlhutlh.
2022-06-26 16:12:47 +00:00
```rust
trait AppendBar {
2024-02-10 17:52:19 +00:00
fn append_bar(self) -> Self;
2022-06-26 16:12:47 +00:00
}
impl AppendBar for String {
2024-02-10 17:52:19 +00:00
fn append_bar(self) -> Self{
format!("{}Bar", self)
}
2022-06-26 16:12:47 +00:00
}
let s = String::from("Foo");
let s = s.append_bar();
println!("s: {}", s);
```
2024-02-10 17:52:19 +00:00
### Qap
#### Introduction
2022-06-26 16:12:47 +00:00
2024-02-10 17:52:19 +00:00
Tests are an essential part of software development. They help ensure that the code behaves as expected and that any changes made to the code do not introduce new bugs or issues. In this section, we will explore the basics of writing tests in Rust.
#### Writing Tests
In Rust, tests are written as functions with the `#[test]` attribute. These functions can be placed in the same file as the code being tested or in a separate file. To run the tests, we can use the `cargo test` command.
Here is an example of a simple test function:
```rust
#[test]
fn test_addition() {
assert_eq!(2 + 2, 4);
}
```
In this example, the `test_addition` function uses the `assert_eq!` macro to check if the sum of 2 and 2 is equal to 4. If the assertion fails, the test will fail.
#### Running Tests
To run the tests, navigate to the project directory in the terminal and run the following command:
```bash
cargo test
```
This command will compile the code and run all the tests in the project. It will display the results of each test, indicating whether it passed or failed.
#### Test Organization
Tests can be organized into modules and submodules, just like regular code. This can help keep the tests organized and make it easier to find and run specific tests.
To create a test module, use the `#[cfg(test)]` attribute above the module declaration. Here is an example:
2022-06-26 16:12:47 +00:00
```rust
#[cfg(test)]
mod tests {
#[test]
2024-02-10 17:52:19 +00:00
fn test_subtraction() {
assert_eq!(5 - 3, 2);
2022-06-27 08:23:29 +00:00
}
}
```
2024-02-10 17:52:19 +00:00
In this example, the `test_subtraction` function is placed inside a test module. To run only the tests in a specific module, use the `cargo test` command followed by the module path. For example:
```bash
cargo test tests
```
This command will run only the tests in the `tests` module.
#### Test Coverage
Test coverage is a measure of how much of the code is covered by tests. It helps identify areas of the code that are not adequately tested and may contain bugs.
To generate a test coverage report in Rust, we can use the `cargo tarpaulin` tool. First, add the `tarpaulin` crate to the `dev-dependencies` section of the `Cargo.toml` file:
```toml
[dev-dependencies]
tarpaulin = "0.17.0"
```
Then, run the following command to generate the test coverage report:
```bash
cargo tarpaulin --all-features
```
The report will show the percentage of code covered by tests and highlight any uncovered lines of code.
#### Conclusion
Writing tests is an important part of software development. In Rust, tests are written as functions with the `#[test]` attribute. They can be organized into modules and submodules to keep them organized. Test coverage can be measured using tools like `cargo tarpaulin` .
```rust
#[cfg(test)]
mod tests {
#[test]
fn you_can_assert() {
assert!(true);
assert_eq!(true, true);
assert_ne!(true, false);
}
}
```
2022-06-27 08:23:29 +00:00
### Threading
#### Arc
2024-02-10 17:52:19 +00:00
**Arc** vItlhutlh **Clone** vItlhutlh vItlhutlh **Arc** vItlhutlh **Clone** vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh vItlhutlh
2022-06-27 08:23:29 +00:00
```rust
use std::sync::Arc;
let apple = Arc::new("the same apple");
for _ in 0..10 {
2024-02-10 17:52:19 +00:00
let apple = Arc::clone(&apple);
thread::spawn(move || {
println!("{:?}", apple);
});
2022-06-27 08:23:29 +00:00
}
```
2024-02-10 17:52:19 +00:00
#### QaD
2022-06-27 08:23:29 +00:00
2024-02-10 17:52:19 +00:00
vaj thread vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vItlhutlhla' vI
2022-06-27 08:23:29 +00:00
```rust
fn main() {
2024-02-10 17:52:19 +00:00
let status = Arc::new(Mutex::new(JobStatus { jobs_completed: 0 }));
let status_shared = Arc::clone(&status);
thread::spawn(move || {
for _ in 0..10 {
thread::sleep(Duration::from_millis(250));
let mut status = status_shared.lock().unwrap();
status.jobs_completed += 1;
}
});
while status.lock().unwrap().jobs_completed < 10 {
println!("waiting... ");
thread::sleep(Duration::from_millis(500));
}
2022-06-26 16:12:47 +00:00
}
```
2024-02-10 17:52:19 +00:00