use crate::{Atom, Ctx, Result, Value};
mod atom;
mod coerce;
mod from;
mod into;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct Coerced<T>(pub T);
pub trait FromJs<'js>: Sized {
fn from_js(ctx: Ctx<'js>, value: Value<'js>) -> Result<Self>;
}
pub trait FromAtom<'js>: Sized {
fn from_atom(atom: Atom<'js>) -> Result<Self>;
}
pub trait FromIteratorJs<'js, A>: Sized {
type Item;
fn from_iter_js<T>(ctx: Ctx<'js>, iter: T) -> Result<Self>
where
T: IntoIterator<Item = A>;
}
pub trait IntoJs<'js> {
fn into_js(self, ctx: Ctx<'js>) -> Result<Value<'js>>;
}
pub trait IntoAtom<'js> {
fn into_atom(self, ctx: Ctx<'js>) -> Atom<'js>;
}
pub trait IteratorJs<'js, A> {
fn collect_js<B>(self, ctx: Ctx<'js>) -> Result<B>
where
B: FromIteratorJs<'js, A>;
}
impl<'js, T, A> IteratorJs<'js, A> for T
where
T: Iterator<Item = A>,
{
fn collect_js<B>(self, ctx: Ctx<'js>) -> Result<B>
where
B: FromIteratorJs<'js, A>,
{
B::from_iter_js(ctx, self)
}
}