Content-Length: 24954 | pFad | https://doc.rust-lang.org/std/string/../error/../string/../iter/../../error_codes/./E0261.html

E0261 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0261

An undeclared lifetime was used.

Erroneous code example:

#![allow(unused)]
fn main() {
// error, use of undeclared lifetime name `'a`
fn foo(x: &'a str) { }

struct Foo {
    // error, use of undeclared lifetime name `'a`
    x: &'a str,
}
}

These can be fixed by declaring lifetime parameters:

#![allow(unused)]
fn main() {
struct Foo<'a> {
    x: &'a str,
}

fn foo<'a>(x: &'a str) {}
}

Impl blocks declare lifetime parameters separately. You need to add lifetime parameters to an impl block if you’re implementing a type that has a lifetime parameter of its own. For example:

#![allow(unused)]
fn main() {
struct Foo<'a> {
    x: &'a str,
}

// error,  use of undeclared lifetime name `'a`
impl Foo<'a> {
    fn foo<'a>(x: &'a str) {}
}
}

This is fixed by declaring the impl block like this:

#![allow(unused)]
fn main() {
struct Foo<'a> {
    x: &'a str,
}

// correct
impl<'a> Foo<'a> {
    fn foo(x: &'a str) {}
}
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/string/../error/../string/../iter/../../error_codes/./E0261.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy