Skip to content

Make it possible for end users to use HashedStr and get their str back - #26434

Draft
DoubleThoughtTheProgrammer wants to merge 3 commits into
bevyengine:mainfrom
DoubleThoughtTheProgrammer:hashedstr-publicly-useful
Draft

DoubleThoughtTheProgrammer wants to merge 3 commits into
bevyengine:mainfrom
DoubleThoughtTheProgrammer:hashedstr-publicly-useful

Conversation

@DoubleThoughtTheProgrammer

@DoubleThoughtTheProgrammer DoubleThoughtTheProgrammer commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Objective

As far as I know, there was no way to go from a HashedStr to a &str for third party crates, despite HashedStr being a pub type. Additionally, there was no way to check equality between two hashed strings, despite that being the main reason why the wrapped Hashed type exists. This limited the usefulness of the type.

This PR allows third party crates to get a &str from HashedStr, and derives PartialEq and Eq.

Solution

Implements Deref<Target = str> for HashedStr and derives PartialEq and Eq.

Testing

  • Did you test these changes? No, as the code change is very trivial. The very fact that it type checks implies that it works as required, in this case.

Showcase

The following should now compile and run in a third-party crate:

fn main() {
    let unhashed_str = "example";
    let hashed_str = bevy::ecs::name::HashedStr::from(unhashed_str);
    assert_eq!(unhashed_str, &*hashed_str);
    assert_eq!(hashed_str, hashed_str);
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant