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.
The error message
Section titled “The error message”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 scopehelp: 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();}What it means
Section titled “What it means”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.
Why Rust does this
Section titled “Why Rust does this”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.
How to fix it
Section titled “How to fix it”Fix 1: Import the trait
Section titled “Fix 1: Import the trait”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 startedThe 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: ANALast guest: Some("CHEN").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.
Fix 3: Call .iter() on the Vec
Section titled “Fix 3: Call .iter() on the Vec”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]Fix 4: Add a trait bound to the generic T
Section titled “Fix 4: Add a trait bound to the generic T”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 parameter2 | 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]Where you’ll usually see it
Section titled “Where you’ll usually see it”- A typo or a method from another language.
tasks.push_back(...)on aVecgiveshelp: you might have meant to use `push`, andtasks.lenght()giveshelp: 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 withno associated function or constant named `new` found for struct `Account`. Fix: addimpl Account { fn new(owner: &str, balance: i64) -> Self { ... } }, or build it directly withAccount { owner: ..., balance: ... }. See Structs. - Calling an associated function with a dot. If
fn new() -> Selfhas noselfparameter,acc.new()fails with “this is an associated function, not a method”. Fix: call it on the type,Account::new().
Related errors
Section titled “Related errors”- E0425: cannot find value in this scope: the name itself isn’t visible, rather than a method on a type.
- E0277: trait bound not satisfied: a type is missing a trait that a function or operator needs. Often shows up next to E0599 in generic code.
- E0308: mismatched types: you have an
Option<T>where aTwas expected, or the other way around. - E0382: use of moved value: a common follow-up after switching from
.iter()to.into_iter(). - All compiler errors: the full list, with a short summary of each.
Quick check
Section titled “Quick check”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
Read more
Section titled “Read more”- E0599 — Rust error codes index: the official explanation of this error.
- Traits: Defining Shared Behavior — The Rust Book: how traits add methods to types, and how trait bounds work.
- Processing a Series of Items with Iterators — The Rust Book:
iter(),into_iter()and iterator methods likemap. Option— Rust standard library: every method for getting a value out of anOption.- The Rust prelude — Rust standard library: the traits that are always in scope, and why
Writeisn’t one of them.