Skip to content

Implement CStr as a pointer rather than a slice #59905

Open
@czipperz

Description

@czipperz

Littered throughout the CStr documentation are notes and hints that it should be eventually converted to using a pointer underneath the hood instead of a slice. This change will make CStr::from_ptr O(1) instead of O(n). Other constructors may still be O(n) because they have to check to ensure there is only one null terminator. If someone wants to try implementing this, it seems like a pretty simple change.

Current struct definition:

pub struct CStr {
    inner: [c_char]
}

Proposed:

pub struct CStr {
    inner: *const c_char
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions