Skip to content

AsRefStr documentation incorrectly states 'static ref is returned #326

@DTrippe

Description

@DTrippe

Just wanted to report that the AsRefStr documentation is wrong. It claims it will create a static str reference, which doesn't seem to be true.

Converts enum variants to &'static str.

The lifetime of the reference is tied to the lifetime of the instance itself. E.,g

#[derive(strum::AsRefStr, strum::IntoStaticStr)]
enum MyVariant {
    A
}

fn main() {
    // Compiles fine
    let variant_str: &'static str = {
        let my_variant = MyVariant::A;
        my_variant.into()
    };
    // Complains that my_variant is dropped while still borrowed
    let variant_str: &'static str = {
        let my_variant = MyVariant::A;
        my_variant.as_ref()
    };
}

Just feel the documentation could be more explicit, and direct people to IntoStaticStr

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions