Compare commits
No commits in common. "b2afa4405d073fd664740c9f44888bd8743fbe23" and "fc5f4f7ca33913e640903a74da43c80e6de588df" have entirely different histories.
b2afa4405d
...
fc5f4f7ca3
@ -11,7 +11,6 @@
|
|||||||
- [BoolStream](./exercises/bool_stream.md)
|
- [BoolStream](./exercises/bool_stream.md)
|
||||||
- [RcChars](./exercises/rcchars.md)
|
- [RcChars](./exercises/rcchars.md)
|
||||||
- [Async Fn](./exercises/async_fn.md)
|
- [Async Fn](./exercises/async_fn.md)
|
||||||
- [Get Functions](./exercises/get_functions.md)
|
|
||||||
- [Chapter 2](./chapter_2.md)
|
- [Chapter 2](./chapter_2.md)
|
||||||
- [AnyStr](./exercises/anystr.md)
|
- [AnyStr](./exercises/anystr.md)
|
||||||
- [Mode](./exercises/mode.md)
|
- [Mode](./exercises/mode.md)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# `From<&T>`
|
|
||||||
|
|
||||||
Make this compile and pass tests:
|
Make this compile and pass tests:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
# Get `Functions`
|
|
||||||
|
|
||||||
Edit the body of `get_functions` to make this compile and pass tests:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
struct Functions {
|
|
||||||
five: fn() -> i32,
|
|
||||||
increment: fn(i32) -> i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_functions() -> &'static Functions {
|
|
||||||
# /*
|
|
||||||
let five = || 5;
|
|
||||||
let increment = |n| n + 1;
|
|
||||||
let functions = Functions { five, increment };
|
|
||||||
&functions
|
|
||||||
# */
|
|
||||||
# &Functions { five: || 5, increment: |n| n + 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_eq!((get_functions().five)(), 5);
|
|
||||||
assert_eq!((get_functions().increment)(4), 5);
|
|
||||||
```
|
|
||||||
|
|
||||||
Try solving it in the playground:
|
|
||||||
|
|
||||||
```rust,editable,compile_fail
|
|
||||||
struct Functions {
|
|
||||||
five: fn() -> i32,
|
|
||||||
increment: fn(i32) -> i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_functions() -> &'static Functions {
|
|
||||||
let five = || 5;
|
|
||||||
let increment = |n| n + 1;
|
|
||||||
let functions = Functions { five, increment };
|
|
||||||
&functions
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert_eq!((get_functions().five)(), 5);
|
|
||||||
assert_eq!((get_functions().increment)(4), 5);
|
|
||||||
}
|
|
||||||
```
|
|
@ -16,7 +16,7 @@ p.s. most of the exercises are actually about `trait`s, this categorisation isn'
|
|||||||
[`RcChars`]: ./exercises/rcchars.md
|
[`RcChars`]: ./exercises/rcchars.md
|
||||||
[extracting lifetimes]: ./exercises/bool_stream.md
|
[extracting lifetimes]: ./exercises/bool_stream.md
|
||||||
[exclusive traits]: ./exercises/multiple_blanket.md
|
[exclusive traits]: ./exercises/multiple_blanket.md
|
||||||
[merging traits]: ./exercises/mode.md
|
[merging traits]: ./exercises/modes.md
|
||||||
[`AnyStr`]: ./exercises/anystr.md
|
[`AnyStr`]: ./exercises/anystr.md
|
||||||
[composition]: ./exercises/composition.md
|
[composition]: ./exercises/composition.md
|
||||||
[`Duration`]: ./exercises/duration.md
|
[`Duration`]: ./exercises/duration.md
|
||||||
|
Loading…
Reference in New Issue
Block a user