extern crate libc;
use std::ffi::CString;
use libc::c_char;
#[cfg(any(
all(feature = "android", target_os = "android"),
all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
))]
extern "C" {
fn platform_log_impl(tag: *const c_char, message: *const c_char);
}
#[cfg(debug_assertions)]
pub fn platform_log<M>(tag: &str, message: M)
where
M: AsRef<str>,
{
#[cfg(any(
all(feature = "android", target_os = "android"),
all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
))]
if let (Ok(tag), Ok(message)) = (CString::new(tag), CString::new(message.as_ref())) {
let c_tag = (&tag).as_ptr();
let c_message = (&message).as_ptr();
unsafe {
platform_log_impl(c_tag, c_message);
}
}
#[cfg(not(any(
all(feature = "android", target_os = "android"),
all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
)))]
println!("{}: {}", tag, message.as_ref());
}
#[cfg(not(debug_assertions))]
pub fn platform_log<M>(tag: &str, message: M)
where
M: AsRef<str>,
{
}