Thanks to visit codestin.com
Credit goes to github.com

Skip to content

How to take ownership of an array of strings allocated in C? #3

@jplatte

Description

@jplatte

The crate documentation says this about MArray<T>:

MArray<T> — A null-terminated array, which can be used to represent e.g. array of C strings terminated by a null pointer.

However, there are no examples anywhere and I can't figure out how to do this. I've been using my own non-generic version of MArray, as well as my own own version of MString (or rather, MBox<CStr>) so far, where I have just casted from *mut *mut c_char to *mut MallocCString, based on the assumption that MallocCString, which is just a tuple struct containing a *mut c_char, has the same representation as the plain *mut c_char. But I'd like to cut down on the amount of stuff I'm reimplementing in my crate, as well as my rather uneducated use of unsafe.

My current code can be found here, for reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions