#![cfg_attr(feature = "unstable_set_ptr_value", feature(set_ptr_value))]
#![deny(missing_docs)]
#[doc = include_str!("../Readme.md")]
#[cfg(doc)]
pub mod docs {}
macro_rules! lifetime_erase_trait_vtable {
((&mut $r:expr): $lt:lifetime as $trait:path) => {{
let vtable = (&mut $r) as &mut (dyn $trait + $lt) as *mut (dyn $trait + $lt);
unsafe { core::mem::transmute::<_, *mut (dyn $trait + 'static)>(vtable) }
}};
}
macro_rules! dyn_setter {
(
impl <$R:ident> $tyfamily:path = self as $self:ident {
$(
$(#[$meta:meta])*
fn $name:ident -> $trait:path = $lhs:expr;
)*
}
) => {
impl<$R> $tyfamily {
$(
$(#[$meta])*
pub fn $name(&mut self)
where $R: $trait
{
let $self = self;
$lhs = Some(lifetime_erase_trait_vtable!((&mut $self.inner): '_ as $trait));
}
)*
}
}
}
macro_rules! dyn_getter {
(
impl$(<$R:ident>)? $tyfamily:path = self as $self:ident {
// Safety requirement: must borrow and create a pointer that is valid for all the
// vtable entries that are used in the body.
unsafe const ptr: $constptr:expr;
// Safety requirement: must mutably borrow and create a pointer that is valid for all
// the vtable entries that are used in the body.
unsafe mut ptr: $mutptr:expr;
} {
$(
$(#[$meta:meta])*
fn $name:ident $({ $(#[$mutmeta:meta])* mut: fn $mut:ident})? -> $trait:path = $lhs:expr;
)*
}
) => {
impl$(<$R: ?Sized>)* $tyfamily {
$(
$(#[$meta])*
pub fn $name(&self) -> Option<&'_ dyn $trait> {
let $self = self;
let raw = $constptr;
let local = WithMetadataOf::with_metadata_of_on_stable(raw, $lhs?);
Some(unsafe { &*local })
}
$(
$(#[$mutmeta])*
pub fn $mut(&mut self) -> Option<&'_ mut dyn $trait> {
let $self = self;
let raw = $mutptr;
let local = WithMetadataOf::with_metadata_of_on_stable(raw, $lhs?);
Some(unsafe { &mut *local })
}
)*
)*
}
}
}
pub mod reader;
pub mod writer;
mod stable_with_metadata_of;
pub use reader::Reader;
pub use writer::Writer;