Update Examples

Glen Whitney 2024-08-27 02:32:06 +00:00
parent ca50e00531
commit dec41efd58

@ -1134,3 +1134,133 @@ fn main
``` ```
</td></tr></table> </td></tr></table>
There doesn't seem to be anything else syntactically relevant in the other subsubsections here, until we get to...
##### Examples in std
**Iterator::any**
<table>
<tr>
<th>Rust</th>
<th>Husht</th>
</tr>
<tr>
<td>
```
pub trait Iterator {
type Item;
fn any<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool;
}
fn main() {
let vec1 = vec![1, 2, 3];
let vec2 = vec![4, 5, 6];
println!("2 in vec1: {}", vec1.iter() .any(|&x| x == 2));
println!("2 in vec2: {}", vec2.into_iter().any(|x| x == 2));
println!("vec1 len: {}", vec1.len());
println!("First element of vec1 is: {}", vec1[0]);
// `into_iter()` does move `vec2` and its elements, so they cannot be used again
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
println!("2 in array1: {}", array1.iter() .any(|&x| x == 2));
println!("2 in array2: {}", array2.into_iter().any(|x| x == 2));
}
```
</td><td>
```
pub trait Iterator
type Item
fn any<F>(&mut self, f: F) -> bool where
F: FnMut(Self::Item) -> bool //! Should we be able to drop the `Self::` here?
}
fn main
let vec1 = vec![1, 2, 3]
vec2 = vec![4, 5, 6]
println! "2 in vec1: {}", vec1.iter() .any(|&x| x == 2));
println!("2 in vec2: {}", vec2.into_iter().any(|x| x == 2));
println!("vec1 len: {}", vec1.len());
println!("First element of vec1 is: {}", vec1[0]);
// `into_iter()` does move `vec2` and its elements, so they cannot be used again
let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
println!("2 in array1: {}", array1.iter() .any(|&x| x == 2));
println!("2 in array2: {}", array2.into_iter().any(|x| x == 2));
}
```
</td></tr></table>
**Searching through iterators**
<table>
<tr>
<th>Rust</th>
<th>Husht</th>
</tr>
<tr>
<td>
```
```
</td><td>
```
```
</td></tr></table>
#### Higher order functions
<table>
<tr>
<th>Rust</th>
<th>Husht</th>
</tr>
<tr>
<td>
```
```
</td><td>
```
```
</td></tr></table>
#### Diverging functions
<table>
<tr>
<th>Rust</th>
<th>Husht</th>
</tr>
<tr>
<td>
```
```
</td><td>
```
```
</td></tr></table>