Skip to content

use &CStr everywhere instead of &str #119

@andrewgazelka

Description

@andrewgazelka

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions