mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-12 23:50:20 +03:00
include new files
This commit is contained in:
parent
083f8275bf
commit
8750cdbfbe
27
vendor/morphic_lib/src/util/bytes_id.rs
vendored
Normal file
27
vendor/morphic_lib/src/util/bytes_id.rs
vendored
Normal 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
91
vendor/morphic_lib/src/util/forward_trait.rs
vendored
Normal file
91
vendor/morphic_lib/src/util/forward_trait.rs
vendored
Normal 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
5
vendor/morphic_lib/src/util/mod.rs
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
#[macro_use]
|
||||
pub mod bytes_id;
|
||||
|
||||
#[macro_use]
|
||||
pub mod forward_trait;
|
Loading…
Reference in New Issue
Block a user