Skip to content

Commit bff65fa

Browse files
committed
[Rust] Add FFI conversions to ID types
1 parent 60133f3 commit bff65fa

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

rust/src/ffi.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ macro_rules! ffi_span {
5959
}
6060

6161
macro_rules! new_id_type {
62-
($name:ident, $inner_type:ty) => {
62+
($(#[$meta:meta])* $name:ident, $inner_type:ty $(, $ffi_type:ty, $ffi_field:ident)?) => {
63+
$(#[$meta])*
6364
#[derive(std::fmt::Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
6465
pub struct $name(pub $inner_type);
6566

@@ -80,5 +81,19 @@ macro_rules! new_id_type {
8081
write!(f, "{}", self.0)
8182
}
8283
}
84+
85+
$(
86+
impl From<$ffi_type> for $name {
87+
fn from(value: $ffi_type) -> Self {
88+
Self(value.$ffi_field)
89+
}
90+
}
91+
92+
impl From<$name> for $ffi_type {
93+
fn from(value: $name) -> Self {
94+
Self { $ffi_field: value.0 }
95+
}
96+
}
97+
)?
8398
};
8499
}

0 commit comments

Comments
 (0)