Use a type-safe helper to cast &str and &[u8] to *const c_char
This commit is contained in:
@@ -392,3 +392,21 @@ pub(crate) fn get_dllimport<'tcx>(
|
||||
tcx.native_library(id)
|
||||
.and_then(|lib| lib.dll_imports.iter().find(|di| di.name.as_str() == name))
|
||||
}
|
||||
|
||||
/// Extension trait for explicit casts to `*const c_char`.
|
||||
pub(crate) trait AsCCharPtr {
|
||||
/// Equivalent to `self.as_ptr().cast()`, but only casts to `*const c_char`.
|
||||
fn as_c_char_ptr(&self) -> *const c_char;
|
||||
}
|
||||
|
||||
impl AsCCharPtr for str {
|
||||
fn as_c_char_ptr(&self) -> *const c_char {
|
||||
self.as_ptr().cast()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsCCharPtr for [u8] {
|
||||
fn as_c_char_ptr(&self) -> *const c_char {
|
||||
self.as_ptr().cast()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user