#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum Atom {
Float(f64),
Symbol(String),
}
macro_rules! atom_from_number_type {
($type:ty) => {
impl From<$type> for Atom {
fn from(value: $type) -> Self {
Self::Float(value.into())
}
}
};
}
macro_rules! atom_from_reference_number_type {
($type:ty) => {
impl From<$type> for Atom {
fn from(value: $type) -> Self {
Self::Float((*value).into())
}
}
};
}
atom_from_number_type!(i8);
atom_from_number_type!(i16);
atom_from_number_type!(i32);
atom_from_number_type!(u8);
atom_from_number_type!(u16);
atom_from_number_type!(u32);
atom_from_number_type!(f32);
atom_from_number_type!(f64);
atom_from_reference_number_type!(&i8);
atom_from_reference_number_type!(&i16);
atom_from_reference_number_type!(&i32);
atom_from_reference_number_type!(&u8);
atom_from_reference_number_type!(&u16);
atom_from_reference_number_type!(&u32);
atom_from_reference_number_type!(&f32);
atom_from_reference_number_type!(&f64);
impl From<String> for Atom {
fn from(s: String) -> Self {
Self::Symbol(s)
}
}
impl From<&String> for Atom {
fn from(s: &String) -> Self {
Self::Symbol(s.clone())
}
}
impl From<&str> for Atom {
fn from(s: &str) -> Self {
Self::Symbol(s.to_owned())
}
}
impl From<char> for Atom {
fn from(c: char) -> Self {
Self::Symbol(c.to_string())
}
}
impl From<&char> for Atom {
fn from(c: &char) -> Self {
Self::Symbol(c.to_string())
}
}
impl std::fmt::Display for Atom {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
Atom::Float(float) => write!(f, "{}", float),
Atom::Symbol(s) => write!(f, "{}", s),
}
}
}
#[derive(Debug)]
pub struct PatchFileHandle(usize);
impl PatchFileHandle {
pub(crate) const fn as_mut_ptr(&self) -> *mut std::ffi::c_void {
self.0 as *mut std::ffi::c_void
}
}
impl From<*mut std::ffi::c_void> for PatchFileHandle {
fn from(ptr: *mut std::ffi::c_void) -> Self {
Self(ptr as usize)
}
}
#[allow(clippy::from_over_into)]
impl Into<*mut std::ffi::c_void> for PatchFileHandle {
fn into(self) -> *mut std::ffi::c_void {
self.0 as *mut std::ffi::c_void
}
}
#[derive(Debug)]
pub struct ReceiverHandle(usize);
impl From<*mut std::ffi::c_void> for ReceiverHandle {
fn from(ptr: *mut std::ffi::c_void) -> Self {
Self(ptr as usize)
}
}
#[allow(clippy::from_over_into)]
impl Into<*mut std::ffi::c_void> for ReceiverHandle {
fn into(self) -> *mut std::ffi::c_void {
self.0 as *mut std::ffi::c_void
}
}