summaryrefslogtreecommitdiff
path: root/rust/src/ffi.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-12-17 21:23:46 -0500
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-01-11 10:36:01 -0800
commit168a3fd34824adc9c6a606cd144219701f15cccf (patch)
tree9bbac31ece5ea6ab6627998d995a77f7f7e2f8e6 /rust/src/ffi.rs
parentca91bc1933976c62d24248f0f7c35af38451ff11 (diff)
[Rust] Replace `log` with `tracing`
- Added more documentation - Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo) - Simplified some misc code This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs.
Diffstat (limited to 'rust/src/ffi.rs')
-rw-r--r--rust/src/ffi.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/rust/src/ffi.rs b/rust/src/ffi.rs
index d337df34..b6124dd4 100644
--- a/rust/src/ffi.rs
+++ b/rust/src/ffi.rs
@@ -20,7 +20,7 @@ macro_rules! ffi_wrap {
use std::process;
panic::catch_unwind(|| $b).unwrap_or_else(|_| {
- log::error!("ffi callback caught panic: {}", $n);
+ tracing::error!("ffi callback caught panic: {}", $n);
process::abort()
})
}};
@@ -30,3 +30,41 @@ pub(crate) fn time_from_bn(timestamp: u64) -> SystemTime {
let m = Duration::from_secs(timestamp);
UNIX_EPOCH + m
}
+
+#[macro_export]
+macro_rules! ffi_span {
+ ($name:expr, $bv:expr) => {{
+ use $crate::binary_view::BinaryViewExt;
+ #[allow(unused_imports)]
+ use $crate::file_metadata::FileMetadata;
+ tracing::info_span!($name, session_id = $bv.file().session_id().0).entered()
+ }};
+ ($name:expr) => {
+ tracing::info_span!($name).entered()
+ };
+}
+
+macro_rules! new_id_type {
+ ($name:ident, $inner_type:ty) => {
+ #[derive(std::fmt::Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
+ pub struct $name(pub $inner_type);
+
+ impl From<$inner_type> for $name {
+ fn from(value: $inner_type) -> Self {
+ Self(value)
+ }
+ }
+
+ impl From<$name> for $inner_type {
+ fn from(value: $name) -> Self {
+ value.0
+ }
+ }
+
+ impl std::fmt::Display for $name {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.0)
+ }
+ }
+ };
+}