pub trait UseCString: SealedUseCString { }Expand description
Helper trait that converts rusts various strings into a zero terminated c string for use with a JNI method.
This trait is implemented for:
&str, String, &String,
CString, CStr, *const c_char,
&OsStr, OsString, &OsString,
&[u8], Vec<u8>,
If the String contains the equivalent of a 0 byte then the string stops at the 0 byte ignoring the rest of the string.
Any non Unicode characters in OsString and its derivatives will be replaced with the Unicode replacement character by using to to_str_lossy fn.
Using non utf-8 binary data in the u8 slices/Vec will not be checked for validity before being converted into a *const c_char!
Using invalid inputs on any call to JNI will result in undefined behavior.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
impl UseCString for &CStr
Passed to JNI as is.
impl UseCString for &CString
Passed to JNI as is.
impl UseCString for &Cow<'_, str>
The buffer is copied unless it contains a 0 byte.
Fast case: last element is 0.
impl UseCString for &OsStr
std only.The OsString is transformed to a String by calling to_string_lossy
and then used just like a Cow<'_, str> would be used.
impl UseCString for &OsString
std only.The OsString is transformed to a String by calling to_string_lossy
and then used just like a Cow<'_, str> would be used.
impl UseCString for &String
The buffer is copied unless it contains a 0 byte.
Fast case: last element is 0.
impl UseCString for &Vec<u8>
The buffer is copied unless it contains a 0 byte.
Fast case: last element is 0.
impl UseCString for &[u8]
The buffer is copied unless it contains a 0 byte.
Fast case: last element is 0.
impl UseCString for &str
The buffer is copied unless it contains a 0 byte.
Fast case: last element is 0.
impl UseCString for ()
Convenience implementation that transforms to a null pointer when used with JNI.
impl UseCString for *const i8
Passed as is to the JVM
§Safety
Must either be null or point to a 0 terminated string.
impl UseCString for *const u8
Passed as is to the JVM
§Safety
Must either be null or point to a 0 terminated string.
impl UseCString for *mut i8
Passed as is to the JVM
§Safety
Must either be null or point to a 0 terminated string.
impl UseCString for *mut u8
Passed as is to the JVM
§Safety
Must either be null or point to a 0 terminated string.
impl UseCString for CString
Passed to JNI as is.
impl UseCString for Cow<'_, str>
The buffer is copied unless it contains a 0 byte.
Fast case: last element is 0.
impl UseCString for OsString
std only.The OsString is transformed to a String by calling to_string_lossy
and then used just like a Cow<'_, str> would be used.
impl UseCString for String
String is extended using reserve_exact if it doesnt contain a 0 element.
Fastest case: last element is 0.
Fast case: buffer has room for one more element.
impl UseCString for Vec<u8>
Vec is extended using reserve_exact if it doesnt contain a 0 element.
Fastest case: last element is 0.
Fast case: buffer has room for one more element.