Skip to content

Improve the API for cstring - rust string conversion and vice-versa #301

@muzarski

Description

@muzarski

While we cannot make use of FFI trait API (we don't have any assumptions about the origin of the char* pointers provided by the user), we could probably utilize CassPtr to some extent. Thanks to that, we would be handling null pointers on a type level (represented as None).

I don't like current API for multiple reasons. One of them is that

pub unsafe fn ptr_to_cstr_n(ptr: *const c_char, size: size_t) -> Option<&'static str> {
    if ptr.is_null() {
        return None;
    }
    std::str::from_utf8(unsafe { std::slice::from_raw_parts(ptr as *const u8, size as usize) }).ok()
}

does not distinguish two scenarios:

  1. pointer is null
  2. provided bytes are non-utf8

In both of these scenarios, we return None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3P3 item - no one uses this most probably, but in the end it's better to implement itenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions