mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-01-26 09:18:42 +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:
|
would look like:
|
||||||
|
|
||||||
<!-- I'll ghost everything except `return Err(e)` in the libreoffice file /Carol -->
|
<!-- 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<()> {
|
# fn foo() -> std::io::Result<()> {
|
||||||
let f = File::open("hello.txt");
|
let f = File::open("hello.txt");
|
||||||
|
|
||||||
@ -143,15 +143,14 @@ the example like this:
|
|||||||
|
|
||||||
<!-- I'll ghost everything except `?` in the libreoffice file /Carol -->
|
<!-- I'll ghost everything except `?` in the libreoffice file /Carol -->
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
#![feature(question_mark)]
|
#![feature(question_mark)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
# fn foo() -> std::io::Result<()> {
|
fn main() {
|
||||||
let f = File::open("hello.txt")?;
|
let f = File::open("hello.txt")?;
|
||||||
# Ok(())
|
}
|
||||||
# }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `?` operator at the end of the `open` call does the same thing as our
|
The `?` operator at the end of the `open` call does the same thing as our
|
||||||
|
Loading…
Reference in New Issue
Block a user