Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/RalfJung/rust-101
/ functions
Functions
176 in github.com/RalfJung/rust-101
⨍
Functions
176
◇
Types & classes
36
Function
main
Now our counter is ready for action.
solutions/src/counter.rs:33
Function
main
This decides which part is actually run.
workspace/src/main.rs:28
Function
main
To actually run the code of some part (after filling in the blanks, if necessary), simply edit the `main` function.
src/main.rs:109
Function
main
Now our counter is ready for action.
src/part15.rs:77
Function
main
We are finally ready to iterate! Remember to edit `main.rs` to run this function.
src/part09.rs:65
Function
main
Now we are ready for the demo. Remember to edit `main.rs` to run it.
src/part11.rs:95
Function
main
Putting it all together:
src/part00.rs:104
Function
main
Finally, we can call the `run` function from the previous part on the options extracted using `get_options`. Edit `main.rs` to call this function. You
src/part14.rs:178
Function
main
Here's a small main function, demonstrating the code above in action. Remember to edit `main.rs` to run it.
src/part10.rs:60
Function
main
()
src/part12.rs:55
Function
main
()
src/part02.rs:142
Function
main
Now we have all the pieces together for testing our rgrep with some hard-coded options. @ We need to call `to_string` on string literals to convert th
src/part13.rs:146
Function
main
If you update your `main.rs` to use part 03, `cargo run` should now ask you for some numbers, and tell you the minimum. Neat, isn't it?
src/part03.rs:96
Function
main
()
src/part01.rs:98
Function
main_f32
()
solutions/src/vec.rs:110
Function
main_i32
()
solutions/src/vec.rs:85
Function
mutable_ref_demo
Here's an example of calling `vec_inc`.
src/part04.rs:117
Method
new
Construct a BigInt from a "small" one.
solutions/src/bigint.rs:56
Method
new
()
solutions/src/callbacks.rs:10
Method
new
()
solutions/src/list.rs:26
Method
new
The constructor should not be surprising.
solutions/src/counter.rs:10
Method
new
The constructor just wraps the constructors of `Arc` and `Mutex`.
src/part15.rs:42
Method
new
@ Let's start with a constructor, creating a `BigInt` from an ordinary integer. @ To create an instance of a struct, we write its name followed by a l
src/part05.rs:34
Method
new
Now we can provide some functions. The constructor should be straight-forward.
src/part11.rs:48
Method
new
()
src/part12.rs:32
Method
new
(o: Option<T>)
src/part02.rs:43
Method
new
A new linked list just contains null pointers. `PhantomData` is how we construct any `PhantomData<T>`.
src/part16.rs:97
Method
next
(&mut self)
solutions/src/list.rs:121
Method
next
(&mut self)
src/part16.rs:163
Function
number_or_default
(n: NumberOrNothing, default: i32)
src/part01.rs:31
Function
ownership_demo
()
src/part04.rs:27
Method
partial_cmp
(&self, other: &Line)
solutions/src/rgrep.rs:32
Method
pop_back
(&mut self)
solutions/src/list.rs:46
Method
pop_front
(&mut self)
solutions/src/list.rs:81
Method
power_of_2
Return the nth power-of-2 as BigInt
solutions/src/bigint.rs:123
Method
print2
(self)
src/part03.rs:122
Function
print_and_count
Remember that we decided to use the `FnMut` trait above? This means our closure could actually mutate its environment. For example, we can use that to
src/part10.rs:106
Function
print_digits_v1
Of course, we don't have to use `for` to apply the iterator. We can also explicitly call `next`.
src/part09.rs:73
Function
print_digits_v2
@ Now, it turns out that this combination of doing a loop and a pattern matching is fairly @ common, and Rust provides some convenient syntactic sugar
src/part09.rs:89
Function
print_enumerated
Sometimes it is useful to know both the position of some element in a list, and its value. That's where the `enumerate` function helps.
src/part10.rs:141
Function
print_with_prefix
Now that we saw how to write a function that operates on closures, let's see how to write a closure.
src/part10.rs:90
Method
push_back
This function adds a new node to the end of the list.
src/part16.rs:102
Function
rust_foo
Technically, we are returning a pointer to the first element. But doesn't that mean that callers have to be careful? Imagine `head` would be a C++ fun
src/part06.rs:132
Function
shared_ref_demo
Now that `vec_min` does not acquire ownership of the vector anymore, we can call it multiple times on the same vector and also do things like
src/part04.rs:84
Function
sort_array
## Arrays @ An *array* in Rust is given by the type `[T; n]`, where `n` is some *fixed* number. So, `[f64; @ 10]` is an array of 10 floating-point num
src/part14.rs:75
Function
sort_nums
Now, we can sort, e.g., an vector of numbers.
src/part14.rs:63
Function
sqr
## Expression-based programming @ For example, consider `sqr`:
src/part01.rs:14
Method
sub
(self, rhs: &'a BigInt)
solutions/src/bigint.rs:229
Function
test_add
()
solutions/src/bigint.rs:322
Function
test_add
[test]*/
src/part08.rs:142
Function
test_drop
()
solutions/src/list.rs:196
Function
test_inc1
()
solutions/src/bigint.rs:364
Method
test_invariant
(&self)
solutions/src/bigint.rs:64
Method
test_invariant
@ It can often be useful to encode the invariant of a data-structure in code, so here @ is a check that detects useless trailing zeros.
src/part05.rs:44
Function
test_iter_mut
()
solutions/src/list.rs:209
Function
test_min
()
solutions/src/bigint.rs:280
Function
test_min
()
src/part07.rs:108
Function
test_overflowing_add
()
solutions/src/bigint.rs:304
Function
test_overflowing_add
`overflow_add` is a sufficiently intricate function that a test case is justified. This should also help you to check your solution of the exercise. [
src/part08.rs:48
Function
test_overflowing_sub
()
solutions/src/bigint.rs:313
Function
test_pop_back
()
solutions/src/list.rs:150
Function
test_pop_front
()
solutions/src/list.rs:168
Function
test_power_of_2
()
solutions/src/bigint.rs:379
Function
test_reentrant
()
solutions/src/callbacks.rs:52
Function
test_sub
()
solutions/src/bigint.rs:337
Function
test_sub_panic1
()
solutions/src/bigint.rs:353
Function
test_sub_panic2
()
solutions/src/bigint.rs:359
Function
test_vec_min
()
solutions/src/bigint.rs:292
Function
test_vec_min
Now we are ready to use `assert_eq!` to test `vec_min`. [test]*/
src/part07.rs:142
Method
to_option
(self)
src/part02.rs:47
Function
vec_min
Return a pointer to the minimal value of `v`.
solutions/src/bigint.rs:11
Function
vec_min
Now we can write `vec_min`.
src/part06.rs:30
Function
vec_min
@ Now we can implement a generic function `vec_min` that works on above trait. @ The code is pretty much straight-forward, and Rust checks that all th
src/part07.rs:17
Function
vec_print
Print all elements in the vector
solutions/src/vec.rs:33
Function
vec_sum
Compute the sum of elements in the vector
solutions/src/vec.rs:24
Function
work_on_variant
@ Now consider the following piece of code. Like above, `n` will be a reference to a part of @ `var`, and since we wrote `ref mut`, the reference will
src/part05.rs:133
← previous
101–176 of 176, ranked by callers