1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Standard extensions to [`rcore`].
//!
//! [`rcore`]: crate::rcore

use std::{error::Error, fmt::Display, sync::Arc};

use crate::func::*;
use crate::mode::*;
use crate::rcore::*;

pub mod atomic;
pub mod atomic_object;
pub mod collections;
pub mod counting;
pub mod inject;
pub mod inlining;
mod local_origin;
pub mod nullable;
pub mod point;
pub mod singular;
pub mod tcast;
pub mod tracing;
pub mod typeless;
mod wrapped_origin;

impl Display for Address {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}@{}", hex(&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 {}