phobos 0.10.0

Fast, powerful Vulkan abstraction library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! String utilities for dealing with FFI strings

use std::ffi::{c_char, CStr, CString};

/// Wraps a c string into a string, or an empty string if the provided c string was null.
/// Assumes the provided c string is null terminated.
pub(crate) unsafe fn wrap_c_str(s: *const c_char) -> String {
    return if s.is_null() {
        String::default()
    } else {
        CStr::from_ptr(s).to_string_lossy().into_owned()
    };
}

/// Safely unwraps a slice of strings into a vec of raw c strings.
pub(crate) fn unwrap_to_raw_strings(strings: &[CString]) -> Vec<*const c_char> {
    strings.iter().map(|string| string.as_ptr()).collect()
}