52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
//! Standard extensions to [`rcore`].
|
|
//!
|
|
//! [`rcore`]: crate::rcore
|
|
|
|
pub mod atomic;
|
|
pub mod atomic_object;
|
|
pub mod cast;
|
|
pub mod collections;
|
|
pub mod inject;
|
|
pub mod inlining;
|
|
mod local_origin;
|
|
pub mod nullable;
|
|
pub mod point;
|
|
pub mod singular;
|
|
pub mod tracing;
|
|
pub mod typeless;
|
|
mod wrapped_origin;
|
|
|
|
use std::{error::Error, fmt::Display, sync::Arc};
|
|
|
|
use crate::func::*;
|
|
use crate::mode::*;
|
|
use crate::rcore::*;
|
|
|
|
impl Display for Address {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{}@{}", hex::encode(self.point), self.index)
|
|
}
|
|
}
|
|
|
|
/// Extension trait for [Serializable]s.
|
|
pub trait SerializableExt: Serializable {
|
|
/// Serialize into a [Vec] of bytes.
|
|
fn bytes(&self) -> Vec<u8> {
|
|
let mut vec = Vec::new();
|
|
self.serialize(&mut vec);
|
|
vec
|
|
}
|
|
}
|
|
|
|
impl<S: Serializable> SerializableExt for S {}
|
|
|
|
/// [`ResolverExt::into_rc`].
|
|
pub trait ResolverExt<'a, Ctx: Context<'a>>: Resolver<'a, Ctx> + Sized {
|
|
/// Wrap the resolver into [`Arc`].
|
|
fn into_rc(self) -> Arc<dyn Resolver<'a, Ctx>> {
|
|
Arc::new(self)
|
|
}
|
|
}
|
|
|
|
impl<'a, Ctx: Context<'a>, R: Resolver<'a, Ctx>> ResolverExt<'a, Ctx> for R {}
|