Skip to content

Rust Error E0599: No Method Named X Found

Error E0599 means you called a method that Rust can’t find on that type. It’s very common, and the cause is usually one of a handful of things: a trait you didn’t import, an Option you didn’t unwrap, a Vec you treated like an iterator, or a simple typo. The good news is that rustc’s help: lines often tell you the exact fix. This page is part of the compiler errors guide.

error[E0599]: no method named `write_all` found for struct `Stdout` in the current scope
--> src/main.rs:5:9
|
5 | out.write_all(b"Server started\n").unwrap();
| ^^^^^^^^^
|
= note: the method is available for `Stdout` here
|
= help: items from traits can only be used if the trait is in scope
help: trait `Write` which provides `write_all` is implemented but not in scope; perhaps you want to import it
|
1 + use std::io::Write;
|

This is the program that produced it:

use std::io;
fn main() {
let mut out = io::stdout();
out.write_all(b"Server started\n").unwrap();
}

The ^^^^ marks the method name, write_all, and the first line tells you the type Rust looked on: Stdout. So the message reads “I looked at Stdout and found no method called write_all that I’m allowed to use here.”

The type in that first line is the most useful clue on the page. If it says Option<T>, Result<T, E>, Vec<_> or a type parameter T when you expected something else, you already know which fix below you need.

In Rust, many methods don’t belong to the type itself. They come from a trait. write_all comes from the Write trait, and Stdout implements it. But a trait’s methods only work in a file that has the trait in scope, usually with a use line. That’s what “items from traits can only be used if the trait is in scope” means.

This rule keeps code predictable. Two crates can each add a method called write_all to the same type through different traits. If every trait were always active, you couldn’t tell which one a call means. With the rule, only the traits you imported count.

The other causes come from Rust’s strict types. An Option<&str> is not a &str, so it doesn’t have &str methods. A generic T could be any type at all, so Rust only lets you call methods that the bounds on T promise.

Choose this when the help says “items from traits can only be used if the trait is in scope”. Add the use line rustc suggests.

use std::io::{self, Write};
fn main() {
let mut out = io::stdout();
out.write_all(b"Server started\n").unwrap();
}

Output:

Server started
▶ Try it Yourself

The same happens with the rand crate. Without the import, rng.random_range(1..=6) fails, and rustc tells you which trait to bring in:

help: trait `RngExt` which provides `random_range` is implemented but not in scope; perhaps you want to import it
|
1 + use rand::RngExt;

Heads up: in rand 0.10 the trait is RngExt. Older tutorials say use rand::Rng, and on rand 0.10 that import gives you this exact same error. Follow the help: line, not the tutorial.

Fix 2: Get the value out of the Option or Result first

Section titled “Fix 2: Get the value out of the Option or Result first”

Choose this when the type in the error is Option<T> or Result<T, E>. The value you want is inside, and you have to take it out before you call its methods.

error[E0599]: no method named `to_uppercase` found for enum `Option<T>` in the current scope
--> src/main.rs:4:39
|
4 | println!("First guest: {}", first.to_uppercase());
| ^^^^^^^^^^^^ method not found in `Option<&&str>`

first() returns an Option, because the list might be empty. rustc suggests .expect(...), which works but crashes on None. Handling both cases is usually better:

fn main() {
let guests = vec!["ana", "bo", "chen"];
match guests.first() {
Some(name) => println!("First guest: {}", name.to_uppercase()),
None => println!("No guests yet"),
}
let shout = guests.last().map(|name| name.to_uppercase());
println!("Last guest: {:?}", shout);
}

Output:

First guest: ANA
Last guest: Some("CHEN")
▶ Try it Yourself

.map() runs your code on the inside value and keeps the Option wrapper. For a Result (for example from .parse()), use match, .unwrap_or(...), or ? inside a function that returns Result. See Option and Result.

Choose this when you call .map(), .filter() or another iterator method directly on a Vec. The error looks different here:

error[E0599]: the method `map` exists for struct `Vec<{integer}>`, but its trait bounds were not satisfied
--> src/main.rs:3:35
|
3 | let curved: Vec<i32> = scores.map(|s| s + 5).collect();
| ^^^
|
= note: the following trait bounds were not satisfied:
`Vec<{integer}>: Iterator`

For some methods, such as filter, the message is friendlier. rustc says the Vec<i32> “is not an iterator” and adds help: call `.into_iter()` first. Same cause, same fix.

Vec<{integer}>: Iterator is “not satisfied” because a Vec is a collection, not an iterator. Ask it for one with .iter() (borrows the items) or .into_iter() (takes them):

fn main() {
let scores = vec![70, 85, 92];
let curved: Vec<i32> = scores.iter().map(|s| s + 5).collect();
println!("{:?}", curved);
}

Output:

[75, 90, 97]
▶ Try it Yourself

Choose this when the error says the method was not found “for type parameter T”. Inside a generic function, Rust only knows what the bounds on T promise. Plain T promises nothing, so it has no methods.

error[E0599]: no method named `to_string` found for type parameter `T` in the current scope
--> src/main.rs:2:26
|
1 | fn describe<T>(item: T) -> String {
| - method `to_string` not found for this type parameter
2 | format!("[{}]", item.to_string())
| ^^^^^^^^^ method cannot be called on `T` due to unsatisfied trait bounds
|
help: the following trait defines an item `to_string`, perhaps you need to restrict type parameter `T` with it:
|
1 | fn describe<T: ToString>(item: T) -> String {
| ++++++++++

Add the bound rustc suggests. Now only types that can be turned into a string are accepted:

fn describe<T: ToString>(item: T) -> String {
format!("[{}]", item.to_string())
}
fn main() {
println!("{}", describe(42));
println!("{}", describe("ready"));
}

Output:

[42]
[ready]
▶ Try it Yourself
  • A typo or a method from another language. tasks.push_back(...) on a Vec gives help: you might have meant to use `push`, and tasks.lenght() gives help: there is a method `len` with a similar name. Fix: use the name rustc suggests.
  • Calling Type::new() that you never wrote. Rust gives no free constructors: Account::new("Ana", 100) fails with no associated function or constant named `new` found for struct `Account`. Fix: add impl Account { fn new(owner: &str, balance: i64) -> Self { ... } }, or build it directly with Account { owner: ..., balance: ... }. See Structs.
  • Calling an associated function with a dot. If fn new() -> Self has no self parameter, acc.new() fails with “this is an associated function, not a method”. Fix: call it on the type, Account::new().

Quick check

1. rustc says "items from traits can only be used if the trait is in scope". What should you do?

2. names.first().to_uppercase() fails with E0599 for Option<&&str>. Why?

3. You call scores.filter(...) on a Vec<i32> and rustc says "Vec<i32> is not an iterator". What's the fix?

Score: 0 / 3