//! Standard extensions to [`crate::core`]. pub mod atomic; pub mod cast; pub mod collections; pub mod fallible; pub mod inlining; mod local_origin; pub mod nullable; pub mod point; pub mod tracing; mod typeless; use std::{error::Error, fmt::Display, rc::Rc}; use crate::core::*; use crate::func::*; impl Display for Address { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!("{}@{}", hex::encode(self.point), self.index)) } } /// Extension trait for [Serializable]s. pub trait ExtSerializable: Serializable { /// Serialize into a [Vec] of bytes. fn bytes(&self) -> Vec; } impl ExtSerializable for S { fn bytes(&self) -> Vec { let mut vec = Vec::new(); self.serialize(&mut vec); vec } } /// Extention trait for simpler conversion between [`Context::T`] and [`Context::Fallible`]. /// /// Until either Rust type system or [`crate::func`] take serious changes, /// this is the preferred way to switch between [Wrapped] and [fallible]. pub trait FallibleContext: Context { /// Convert a fallible wrapped into a wrapped result. fn unstuff<'a, A: 'a, E: 'a>( wa: <::W as WeakFunctor>::F<'a, A>, ) -> ::F<'a, Result> where Self: 'a; /// Convert a wrapped result into a fallible wrapped. fn stuff<'a, A: 'a, E: 'a>( fa: ::F<'a, Result>, ) -> <::W as WeakFunctor>::F<'a, A> where Self: 'a; } impl FallibleContext for Ctx { fn unstuff<'a, A: 'a, E: 'a>( wa: <::W as WeakFunctor>::F<'a, A>, ) -> ::F<'a, Result> where Self: 'a, { Self::Fallible::unstuff(wa) } fn stuff<'a, A: 'a, E: 'a>( fa: ::F<'a, Result>, ) -> <::W as WeakFunctor>::F<'a, A> where Self: 'a, { Self::Fallible::stuff(fa) } }