java_asm 0.1.3

Java bytecode reader & writer in rust
Documentation
use crate::StrRef;
use std::sync::Arc;

pub trait ToStringRef {
    fn to_ref(&self) -> StrRef;
}

impl<T: ToStringRef> ToStringRef for &T {
    #[inline]
    fn to_ref(&self) -> StrRef { (*self).to_ref() }
}

impl ToStringRef for StrRef {
    #[inline]
    fn to_ref(&self) -> StrRef { Arc::clone(self) }
}

impl ToStringRef for str {
    #[inline]
    fn to_ref(&self) -> StrRef { Arc::from(self) }
}

impl ToStringRef for String {
    #[inline]
    fn to_ref(&self) -> StrRef { Arc::from(self.as_str()) }
}

macro_rules! to_str_ref_impls {
    { $($ty:ty,)* } => {
        $(
            impl ToStringRef for $ty {
                #[inline]
                fn to_ref(&self) -> StrRef { StrRef::from(self.to_string()) }
            }
        )*
    };
}

to_str_ref_impls!(
    i8, i16, i32, i64, i128, isize,
    u8, u16, u32, u64, u128, usize,
    f32, f64, char, bool, &'static str,
);

#[macro_export]
macro_rules! vec_str_ref {
    () => (
        Vec::new()
    );
    ($($x:expr),+ $(,)?) => (
        vec![$($x),+].iter().map(|s| (*s).into()).collect::<Vec<StrRef>>()
    );
}