| Crates.io | c3ne-types |
| lib.rs | c3ne-types |
| version | 0.1.0 |
| created_at | 2025-10-13 02:30:15.626262+00 |
| updated_at | 2025-10-13 02:30:15.626262+00 |
| description | c3ne-types is a helper crate for users of the main c3ne crate that provides an implementation of the messier C3 types for use in Rust. |
| homepage | |
| repository | https://github.com/TheDreamer123/c3ne-types |
| max_upload_size | |
| id | 1879929 |
| size | 9,062 |
c3ne-types provides a way to interface with certain messy types from C3 without the need of implementing them yourself.
At the time of writing, all String types have been implemented, even if roughly.
String. You can create a variable of this type using the C3String::into_c3_string function:
let my_c3string = C3String::into_c3_string("Hello there!");
It can also be converted to a string slice by using the str_from_c3_string function:
let string_slice = my_c3string.str_from_c3_string().unwrap();
ZString. You can create a variable of this type using the C3String::into_c3_zstring function:
let my_c3_zstring = C3String::into_c3_zstring("Hello there!");
It can also be converted to a string slice by using the C3String::str_from_c3_zstring function:
let string_slice = CString::str_from_c3_zstring(my_c3_zstring)).unwrap();
WString. You can create a variable of this type using the C3String::into_c3_wstring function:
let my_c3_wstring = C3String::into_c3_wstring("Hello there!");
It can also be converted to a string slice by using the C3String::str_from_c3_wstring function:
let string_slice = CString::str_from_c3_wstring(my_c3_wstring)).unwrap();
DString. You can create a variable of this type using the C3String::into_c3_dstring function:
let my_c3_dstring = C3String::into_c3_dstring("Hello there!");
It can also be converted to a string slice by using the C3String::str_from_c3_dstring function:
let string_slice = CString::str_from_c3_dstring(my_c3_dstring)).unwrap();
While it is not very difficult to use them, you can follow these steps to verify they work:
[dependencies]
c3ne-types = "0.1.0"
# ...
person.c3 in your directory of choosing with the following code:module person @export;
import std::io;
struct Person
{
int age;
String name;
}
fn Person newPerson(int age, String name) @extern("newPerson")
{
return { age, name };
}
fn void printInfo(Person *p) @extern("printInfo")
{
io::printfn("Age: %d\nName: %s", p.age, p.name);
}
src/main.rs:use c3ne_types::C3String;
use std::ffi::c_int;
#[repr(C)]
struct Person {
age: c_int,
name: C3String,
}
unsafe extern "system" {
fn newPerson(age: c_int, name: C3String) -> Person;
fn printInfo(p: *const Person);
}
fn main() {
unsafe {
let p: Person = newPerson(22, C3String::into_c3_string("John Doe"));
printInfo(&p);
println!("{}", &p.name.str_from_c3_string().unwrap());
}
}
p.name to ZString in your C3 code once you get to WString and DString!