Use a type-safe helper to cast &str
and &[u8]
to *const c_char
This commit is contained in:
parent
66701c4226
commit
4bd84b23a8
17 changed files with 110 additions and 87 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue