refactor!: better scoping of arguments in host_fn macro, allow visibility in macros to be specified (#621)

Fixes #619  

- Also updates `host_fn`, `encoding`, and `typed_plugin` macros to allow
for visibility specifiers to manage the visibility of the defined types.
This means that `pub` will need to be added to existing invocations that
should remain public
This commit is contained in:
zach
2023-12-05 09:58:35 -08:00
committed by GitHub
parent b1cb80fb47
commit 9bff8be915
5 changed files with 34 additions and 22 deletions

View File

@@ -15,10 +15,10 @@ use base64::Engine;
/// and `FromBytesOwned` using `serde_json::from_vec`
#[macro_export]
macro_rules! encoding {
($name:ident, $to_vec:expr, $from_slice:expr) => {
($pub:vis $name:ident, $to_vec:expr, $from_slice:expr) => {
#[doc = concat!(stringify!($name), " encoding")]
#[derive(Debug)]
pub struct $name<T>(pub T);
$pub struct $name<T>(pub T);
impl<T> $name<T> {
pub fn into_inner(self) -> T {
@@ -50,10 +50,10 @@ macro_rules! encoding {
};
}
encoding!(Json, serde_json::to_vec, serde_json::from_slice);
encoding!(pub Json, serde_json::to_vec, serde_json::from_slice);
#[cfg(feature = "msgpack")]
encoding!(Msgpack, rmp_serde::to_vec, rmp_serde::from_slice);
encoding!(pub Msgpack, rmp_serde::to_vec, rmp_serde::from_slice);
impl<'a> ToBytes<'a> for serde_json::Value {
type Bytes = Vec<u8>;