mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-01-25 00:18:46 +08:00
Make these code examples build off each other
Yes, this means we can't test these, but imo this makes more sense.
This commit is contained in:
parent
79bac99c21
commit
b88aad0d98
@ -121,9 +121,9 @@ you can return the error to the calling function. Within your function, that
|
||||
would look like:
|
||||
|
||||
<!-- I'll ghost everything except `return Err(e)` in the libreoffice file /Carol -->
|
||||
```rust
|
||||
use std::fs::File;
|
||||
|
||||
```rust,ignore
|
||||
# use std::fs::File;
|
||||
# fn foo() -> std::io::Result<()> {
|
||||
let f = File::open("hello.txt");
|
||||
|
||||
@ -143,15 +143,14 @@ the example like this:
|
||||
|
||||
<!-- I'll ghost everything except `?` in the libreoffice file /Carol -->
|
||||
|
||||
```rust
|
||||
```rust,ignore
|
||||
#![feature(question_mark)]
|
||||
|
||||
use std::fs::File;
|
||||
|
||||
# fn foo() -> std::io::Result<()> {
|
||||
let f = File::open("hello.txt")?;
|
||||
# Ok(())
|
||||
# }
|
||||
fn main() {
|
||||
let f = File::open("hello.txt")?;
|
||||
}
|
||||
```
|
||||
|
||||
The `?` operator at the end of the `open` call does the same thing as our
|
||||
|
Loading…
Reference in New Issue
Block a user