Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should accesskit use Box<str>? #444

Open
PoignardAzur opened this issue Aug 14, 2024 · 2 comments
Open

Should accesskit use Box<str>? #444

PoignardAzur opened this issue Aug 14, 2024 · 2 comments

Comments

@PoignardAzur
Copy link
Contributor

A lot of accesskit APIs end up using Box<str> as their string type, which is not very idiomatic for Rust.

As far as I can tell, the reason is to save space in the PropertyValue enum. But that enum also has a few variants that are as large or larger than a String, meaning storing a Box<str> doesn't actually save space:

  • NodeIdVec has a Vec.
  • The Rect variant holds 4 f64
  • CustomActionVec has a Vec.

Should these variants be boxed? As far as I can tell every other type is two pointers long at most.

@drewcrawford
Copy link
Contributor

For what it's worth, I was momentarily confused by this today. String feels more idiomatic for what I was doing, but I don't know the history.

@mwcampbell
Copy link
Contributor

I'm actually planning to change the property setters to take a &str instead. That means that the string will always be copied, but it's simpler from the user's perspective. I had bundled this with a bigger refactor that would reduce temporary memory allocations, but could do this one thing as a standalone change.

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

No branches or pull requests

3 participants