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

use &CStr everywhere instead of &str #119

Open
andrewgazelka opened this issue Jul 4, 2024 · 1 comment
Open

use &CStr everywhere instead of &str #119

andrewgazelka opened this issue Jul 4, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@andrewgazelka
Copy link
Contributor

In Rust 1.77.0, C-string literals have been stabilized and can be created with c"foo".
As such, using CStrs are easy to create, and I believe we should aim to be as zero-cost as possible when it comes to our bindings.

  • Applying format_compact! to a str is a non-zero cost operation, even if the str is small.
  • My intuition tells be 90% of the time when using &'a str, 'a is 'static.

This would also allow us to unify the APIs that have two functions: one that takes a &str and one that takes a &CStr. There are many functions
that do not even have a c_str equivalent, and this is personally an issue for me.

I also am slightly against the idea of using generics to accept CStr and str. Again, this will make newcomers more likely to use the much less efficient &str everywhere
when it makes no sense to do so.

@Indra-db
Copy link
Owner

This used to be &CStr, but from alpha user experience, I noticed it's not ideal and people are too unfamiliar with it. With compact string, the cost has been greatly reduced in most cases and thus it shouldn't be an issue in 99.9% of the cases considering the fact you aren't likely to use names in hot path code, but more likely setup code.

In the future we can consider some sort of Into trait to support both.

@Indra-db Indra-db added enhancement New feature or request good first issue Good for newcomers labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants