include new files

This commit is contained in:
Folkert 2021-05-19 23:02:27 +02:00
parent 083f8275bf
commit 8750cdbfbe
3 changed files with 123 additions and 0 deletions

27
vendor/morphic_lib/src/util/bytes_id.rs vendored Normal file
View File

@ -0,0 +1,27 @@
macro_rules! bytes_id {
(
// Capturing attributes allows us to capture doc comments
$(#[$annot_borrowed:meta])* $borrowed_vis:vis $borrowed:ident;
$(#[$annot_owned:meta])* $owned_vis:vis $owned:ident;
) => {
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
$(#[$annot_borrowed])*
$borrowed_vis struct $borrowed<'a>($borrowed_vis &'a [u8]);
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
$(#[$annot_owned])*
$owned_vis struct $owned($owned_vis ::std::vec::Vec<u8>);
impl $owned {
fn borrowed<'a>(&'a self) -> $borrowed<'a> {
$borrowed(&self.0)
}
}
impl<'a> ::std::convert::From<$borrowed<'a>> for $owned {
fn from(borrowed: $borrowed<'a>) -> Self {
$owned(<[u8]>::to_vec(&borrowed.0))
}
}
}
}

View File

@ -0,0 +1,91 @@
macro_rules! forward_trait {
(
$(#[$annot:meta])*
$t_vis:vis trait $t_name:ident {
$($methods:tt)*
}
$($impls:tt)*
) => {
$(#[$annot])*
$t_vis trait $t_name { $($methods)* }
forward_trait_impls!(trait $t_name { $($methods)* } $($impls)*);
};
}
macro_rules! forward_trait_impls {
(
trait $t_name:ident { $($methods:tt)* }
) => {
// Base case: no impls left
};
(
trait $t_name:ident { $($methods:tt)* }
impl $wrapper:ident => .$field:ident;
$($impls:tt)*
) => {
impl $t_name for $wrapper {
forward_trait_impl_body!( { $($methods)* } .$field );
}
forward_trait_impls!(trait $t_name { $($methods)* } $($impls)*);
}
}
macro_rules! forward_trait_impl_body {
(
{}
.$field:ident
) => {
// Base case: no methods left
};
(
{
$(#[$annot:meta])*
fn $fn_name:ident(self $(, $arg_name:ident : $arg_ty:ty)* $(,)? ) -> $ret_ty:ty ;
$($methods:tt)*
}
.$field:ident
) => {
fn $fn_name(self, $($arg_name: $arg_ty),*) -> $ret_ty {
self.$field.$fn_name($($arg_name),*)
}
forward_trait_impl_body!({ $($methods)* } .$field);
};
(
{
$(#[$annot:meta])*
fn $fn_name:ident(&self $(, $arg_name:ident : $arg_ty:ty)* $(,)? ) -> $ret_ty:ty ;
$($methods:tt)*
}
.$field:ident
) => {
fn $fn_name(&self, $($arg_name: $arg_ty),*) -> $ret_ty {
self.$field.$fn_name($($arg_name),*)
}
forward_trait_impl_body!({ $($methods)* } .$field);
};
(
{
$(#[$annot:meta])*
fn $fn_name:ident(&mut self $(, $arg_name:ident : $arg_ty:ty)* $(,)? ) -> $ret_ty:ty ;
$($methods:tt)*
}
.$field:ident
) => {
fn $fn_name(&mut self, $($arg_name: $arg_ty),*) -> $ret_ty {
self.$field.$fn_name($($arg_name),*)
}
forward_trait_impl_body!({ $($methods)* } .$field);
};
}

5
vendor/morphic_lib/src/util/mod.rs vendored Normal file
View File

@ -0,0 +1,5 @@
#[macro_use]
pub mod bytes_id;
#[macro_use]
pub mod forward_trait;