![]() The return string is then converted into a CString and passed back into C code. We then append the provided string on the end of our greeting string to create our return string. If an error has occurred, then no arg was provided and we substitute there, otherwise we use the value of the provided string. We then convert it to a str and check the result. First we create a CStr object from the pointer. We have to then convert the string from a C string to a Rust str. The string that rust_greeting accepts is a pointer to a C char array. # tells the compiler not to mangle the function name as it usually does by default, ensuring our function name is exported as if it had been written in C.Įxtern tells the Rust compiler that this function will be called from outside of Rust and to therefore ensure that it is compiled using C calling conventions. Let’s take a look at what is going on here.Īs we will be calling this library from non-Rust code, we will actually be calling it through a C bridge.
0 Comments
Leave a Reply. |