X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/ab7f9b241429bd675b437d2437799de75d2f409b..2dac37ce49abc1a890aa79fb15bf837b4cf1ca64:/src/part11.rs diff --git a/src/part11.rs b/src/part11.rs index 9d931db..757f205 100644 --- a/src/part11.rs +++ b/src/part11.rs @@ -23,7 +23,7 @@ struct CallbacksV1 { //@ But, Rust complains about this definition. It says something about "Sized". What's the trouble? See, for many things we want to do, it is crucial that //@ Rust knows the precise, fixed size of the type - that is, how large this type will be when represented in memory. For example, for a `Vec`, the //@ elements are stored one right after the other. How should that be possible, without a fixed size? The point is, `FnMut(i32)` could be of any size. -//@ We don't know how large that "type that implemenets `FnMut(i32)`" is. Rust calls this an *unsized* type. Whenever we introduce a type variable, Rust +//@ We don't know how large that "type that implements `FnMut(i32)`" is. Rust calls this an *unsized* type. Whenever we introduce a type variable, Rust //@ will implicitly add a bound to that variable, demanding that it is sized. That's why we did not have to worry about this so far.
//@ You can opt-out of this implicit bound by saying `T: ?Sized`. Then `T` may or may not be sized. @@ -115,6 +115,6 @@ pub fn main() { // **Exercise 11.1**: We made the arbitrary choice of using `i32` for the arguments. Generalize the data structures above // to work with an arbitrary type `T` that's passed to the callbacks. Since you need to call multiple callbacks with the -// same `t: T`, you will either have to restrict `T` to `Copy` types, or pass a reference. +// same `val: T` (in our `call` function), you will either have to restrict `T` to `Copy` types, or pass a reference. //@ [index](main.html) | [previous](part10.html) | [raw source](workspace/src/part11.rs) | [next](part12.html)