MCPcopy Create free account

hub / github.com/RalfJung/rust-101 / functions

Functions176 in github.com/RalfJung/rust-101

Functionmain
Now our counter is ready for action.
solutions/src/counter.rs:33
Functionmain
This decides which part is actually run.
workspace/src/main.rs:28
Functionmain
To actually run the code of some part (after filling in the blanks, if necessary), simply edit the `main` function.
src/main.rs:109
Functionmain
Now our counter is ready for action.
src/part15.rs:77
Functionmain
We are finally ready to iterate! Remember to edit `main.rs` to run this function.
src/part09.rs:65
Functionmain
Now we are ready for the demo. Remember to edit `main.rs` to run it.
src/part11.rs:95
Functionmain
Putting it all together:
src/part00.rs:104
Functionmain
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
Functionmain
Here's a small main function, demonstrating the code above in action. Remember to edit `main.rs` to run it.
src/part10.rs:60
Functionmain
()
src/part12.rs:55
Functionmain
()
src/part02.rs:142
Functionmain
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
Functionmain
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
Functionmain
()
src/part01.rs:98
Functionmain_f32
()
solutions/src/vec.rs:110
Functionmain_i32
()
solutions/src/vec.rs:85
Functionmutable_ref_demo
Here's an example of calling `vec_inc`.
src/part04.rs:117
Methodnew
Construct a BigInt from a "small" one.
solutions/src/bigint.rs:56
Methodnew
()
solutions/src/callbacks.rs:10
Methodnew
()
solutions/src/list.rs:26
Methodnew
The constructor should not be surprising.
solutions/src/counter.rs:10
Methodnew
The constructor just wraps the constructors of `Arc` and `Mutex`.
src/part15.rs:42
Methodnew
@ 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
Methodnew
Now we can provide some functions. The constructor should be straight-forward.
src/part11.rs:48
Methodnew
()
src/part12.rs:32
Methodnew
(o: Option<T>)
src/part02.rs:43
Methodnew
A new linked list just contains null pointers. `PhantomData` is how we construct any `PhantomData<T>`.
src/part16.rs:97
Methodnext
(&mut self)
solutions/src/list.rs:121
Methodnext
(&mut self)
src/part16.rs:163
Functionnumber_or_default
(n: NumberOrNothing, default: i32)
src/part01.rs:31
Functionownership_demo
()
src/part04.rs:27
Methodpartial_cmp
(&self, other: &Line)
solutions/src/rgrep.rs:32
Methodpop_back
(&mut self)
solutions/src/list.rs:46
Methodpop_front
(&mut self)
solutions/src/list.rs:81
Methodpower_of_2
Return the nth power-of-2 as BigInt
solutions/src/bigint.rs:123
Methodprint2
(self)
src/part03.rs:122
Functionprint_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
Functionprint_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
Functionprint_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
Functionprint_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
Functionprint_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
Methodpush_back
This function adds a new node to the end of the list.
src/part16.rs:102
Functionrust_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
Functionshared_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
Functionsort_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
Functionsort_nums
Now, we can sort, e.g., an vector of numbers.
src/part14.rs:63
Functionsqr
## Expression-based programming @ For example, consider `sqr`:
src/part01.rs:14
Methodsub
(self, rhs: &'a BigInt)
solutions/src/bigint.rs:229
Functiontest_add
()
solutions/src/bigint.rs:322
Functiontest_add
[test]*/
src/part08.rs:142
Functiontest_drop
()
solutions/src/list.rs:196
Functiontest_inc1
()
solutions/src/bigint.rs:364
Methodtest_invariant
(&self)
solutions/src/bigint.rs:64
Methodtest_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
Functiontest_iter_mut
()
solutions/src/list.rs:209
Functiontest_min
()
solutions/src/bigint.rs:280
Functiontest_min
()
src/part07.rs:108
Functiontest_overflowing_add
()
solutions/src/bigint.rs:304
Functiontest_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
Functiontest_overflowing_sub
()
solutions/src/bigint.rs:313
Functiontest_pop_back
()
solutions/src/list.rs:150
Functiontest_pop_front
()
solutions/src/list.rs:168
Functiontest_power_of_2
()
solutions/src/bigint.rs:379
Functiontest_reentrant
()
solutions/src/callbacks.rs:52
Functiontest_sub
()
solutions/src/bigint.rs:337
Functiontest_sub_panic1
()
solutions/src/bigint.rs:353
Functiontest_sub_panic2
()
solutions/src/bigint.rs:359
Functiontest_vec_min
()
solutions/src/bigint.rs:292
Functiontest_vec_min
Now we are ready to use `assert_eq!` to test `vec_min`. [test]*/
src/part07.rs:142
Methodto_option
(self)
src/part02.rs:47
Functionvec_min
Return a pointer to the minimal value of `v`.
solutions/src/bigint.rs:11
Functionvec_min
Now we can write `vec_min`.
src/part06.rs:30
Functionvec_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
Functionvec_print
Print all elements in the vector
solutions/src/vec.rs:33
Functionvec_sum
Compute the sum of elements in the vector
solutions/src/vec.rs:24
Functionwork_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
← previous101–176 of 176, ranked by callers