alef 0.23.33

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let {{ rs_name }} = if {{ name }}.is_null() {
    None
} else {
    // SAFETY: null check above guarantees {{ name }} is a valid pointer; string is valid UTF-8 from caller.
    match unsafe { CStr::from_ptr({{ name }}) }.to_str() {
{%- if is_ref %}
        Ok(s) => Some(s.to_string()),
{%- else %}
        Ok(s) => Some(std::path::PathBuf::from(s)),
{%- endif %}
        Err(_) => {
            set_last_error(1, "Invalid UTF-8 in parameter '{{ name }}'");
            {{ fail_ret }}
        }
    }
};