MCPcopy Create free account

hub / github.com/RalfJung/rust-101 / types & classes

Types & classes36 in github.com/RalfJung/rust-101

↓ 1 callersClassConcurrentCounter
solutions/src/counter.rs:6
↓ 1 callersClassConcurrentCounter
src/part15.rs:38
InterfaceAction
So, let us define a trait that demands that the type provides some method `do_action` on digits. @ This immediately raises the question: How do we pas
src/part10.rs:17
ClassBigInt
solutions/src/bigint.rs:22
ClassBigInt
@ To write this down in Rust, we use a `struct`, which is a lot like structs in C: @ Just a bunch of named fields. Every field can be private to the c
src/part05.rs:25
ClassCallbacks
solutions/src/callbacks.rs:5
ClassCallbacks
@ So, what can we do, if we can't store the callbacks in a vector? We can put them in a box. @ Semantically, `Box<T>` is a lot like `T`: You fully own
src/part11.rs:42
ClassCallbacks
src/part12.rs:27
ClassCallbacksMut
src/part12.rs:125
ClassCallbacksV1
@ First of all, we need to find a way to store the callbacks. Clearly, there will be a `Vec` @ involved, so that we can always grow the number of regi
src/part11.rs:13
ClassDropChecker
solutions/src/list.rs:186
ClassIter
@ In writing this down, we again have to be explicit about the lifetime of the reference: We @ can't just have an `Iter`, we must have an `Iter<'a>` t
src/part09.rs:30
ClassIterMut
solutions/src/list.rs:113
ClassIterMut
@ For Rust to accept the type, we have to add two more annotations. First of all, we have to @ ensure that the data in the list lives at least as long
src/part16.rs:152
ClassLine
solutions/src/rgrep.rs:20
ClassLinkedList
solutions/src/list.rs:19
ClassLinkedList
The linked list itself stores pointers to the first and the last node. In addition, we tell Rust that this type will own data of type `T`. @ The type
src/part16.rs:57
InterfaceMinimum
This trait is used to compute the minimum of two elements of the given type
solutions/src/vec.rs:50
InterfaceMinimum
solutions/src/bigint.rs:5
InterfaceMinimum
@ So, as a first step towards a generic `vec_min`, we define a `Minimum` trait. @ For now, just ignore the `Copy`, we will come back to this point lat
src/part02.rs:73
InterfaceMinimum
With our new knowledge of lifetimes, we are now able to write down the desired type of `min`: @ We want the function to take two references *with the
src/part07.rs:10
ClassNode
solutions/src/list.rs:12
ClassNode
@ As usually, we start by defining the types. Everything is parameterized by the type `T` of the @ data stored in the list. A node of the list consist
src/part16.rs:35
EnumNumberOrNothing
A number, or nothing
solutions/src/vec.rs:5
EnumNumberOrNothing
An `enum` for "a number or nothing" could look as follows:
src/part00.rs:19
EnumNumberOrNothing
@ And the same applies to case distinction with `match`: Every `arm` of the match @ gives the expression that is returned in the respective case. @ (W
src/part01.rs:26
ClassOptions
solutions/src/rgrep.rs:14
ClassOptions
src/part13.rs:29
EnumOutputMode
solutions/src/rgrep.rs:7
EnumOutputMode
src/part13.rs:22
InterfacePrint
solutions/src/vec.rs:160
InterfacePrint
Exercise 03.1**: The goal is to write a generic version of `SomethingOrNothing::print`. To this end, define a trait `Print` that provides (simple) gen
src/part03.rs:115
ClassPrintWithString
@ As the next step, we need to come up with some action, and write an appropriate implementation @ of `Action` for it. So, let's say we want to print
src/part10.rs:38
EnumSomethingOrNothing
A polymorphic (generic) "some value, or no value"
solutions/src/vec.rs:42
EnumSomethingOrNothing
@ The solution to this is called *generics* or *polymorphism* (the latter is Greek, @ meaning "many shapes"). You may know something similar from C++
src/part02.rs:15
EnumVariant
## Mutation + aliasing considered harmful (part 2) @ Now that we know how to create references to contents of an `enum` (like `v` above), there's @ an
src/part05.rs:125