Skip to content

Can't use unsafe in bsn expression #24121

@Freyja-moth

Description

@Freyja-moth

Bevy version and features

main

What you did

#[derive(Component, Clone)]
pub struct Value(NonZeroU8);

impl Default for Value {
    fn default() -> Self {
        Self(unsafe { NonZeroU8::new_unchecked(1) })
    }
}

fn value() -> impl Scene {
    bsn! {
        Value(unsafe { NonZeroU8::new_unchecked(4) })
    }
}

What went wrong

error: Unexpected input: Invalid BsnValue. This does not match any expected BSN value type.
  --> src/main.rs:10:23
   |
10 |                 Value(unsafe { NonZeroU8::new_unchecked(4) })
   |                       ^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ScenesComposing and serializing ECS objectsC-BugAn unexpected or incorrect behaviorD-MacrosCode that generates Rust codeS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed upon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions