Skip to content

static item example being an &str is confusing #2714

Open
@fw-immunant

Description

@fw-immunant

The slide on statics gives this example:

static BANNER: &str = "Welcome to RustOS 3.14";

Then it describes how the item has a stable address. While this is true, it's confusing because the visible part of the value (the string data) is not actually stored in the static, and the string data itself has a fixed address not due to being part of a static but merely because that's how string literals work.

It would be a bit clearer if we used a type with no indirections such as u32 or [u8; N] so that there aren't multiple layers of pointers involved. Perhaps something like:

static BANNER: [u8; 22] = *b"Welcome to RustOS 3.14";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions