Skip to content

Should static variables be annotated &'static or not? #2689

Closed
@wpd

Description

@wpd

According to the text in src/ch19-01-unsafe-rust.md, "we must annotate the variable’s type, which is &'static str", but the example shown in listings/ch19-advanced-features/listing-19-09/src/main.rs is:

static HELLO_WORLD: &str = "Hello, world!";

fn main() {
    println!("name is: {}", HELLO_WORLD);
}

which does not declare HELLO_WORLD as &'static str. This could be confusing to other newbies (besides myself :-) ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions