Skip to content

Update doc examples that use ? (Carrier) to use Termination #49233

Closed
@frewsxcv

Description

@frewsxcv

Blocked on #49162

Example:

rust/src/libstd/fs.rs

Lines 40 to 49 in c19264f

/// ```no_run
/// use std::fs::File;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt")?;
/// file.write_all(b"Hello, world!")?;
/// # Ok(())
/// # }
/// ```

Instead of:

use std::fs::File;
use std::io::prelude::*;

# fn foo() -> std::io::Result<()> {
let mut file = File::create("foo.txt")?;
file.write_all(b"Hello, world!")?;
# Ok(())
# }

We can now do:

use std::fs::File;
use std::io::Error;
use std::io::prelude::*;

fn main() -> Result<(), Error> {
    let mut file = File::create("foo.txt")?;
    file.write_all(b"Hello, world!")?;
    Ok(())
}

Which can be copied/pasted straight from the docs such that it will compile, unlike the old example

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions