Syntax

Rust Result and ? Syntax

In Rust, result and ?: returns errors up the call stack — let text = std::fs::read_to_string("a.txt")?;

Quick Answer

Syntax
let text = std::fs::read_to_string("a.txt")?;
RustSyntax

Result and ?

Code example
let text = std::fs::read_to_string("a.txt")?;

Returns errors up the call stack.

Learn More

How to result and ? in Rust

  1. Open your Rust file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Rust Result and ? Syntax

Use let text = std::fs::read_to_string("a.txt")?;.

Related Syntax References

Frequently asked questions

What is the Rust syntax for result and ??

Use this pattern: let text = std::fs::read_to_string("a.txt")?;

Can I copy this Rust code example?

Yes. Use Copy code and adapt the example to your program.

Is this Rust syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify