#[cfg(not(target_arch = "wasm32"))]
pub use abi_stable::*;
#[cfg(target_arch = "wasm32")]
pub mod std_types {
pub type RString = String;
pub type RDuration = Duration;
use std::collections::hash_map::RandomState;
pub type RVec<T> = Vec<T>;
pub trait FromSliceExt<T> {
fn from_slice(slice: &[T]) -> Self
where
T: Clone;
}
impl<T> FromSliceExt<T> for RVec<T> {
fn from_slice(slice: &[T]) -> Self
where
T: Clone,
{
Vec::from(slice)
}
}
pub type RStr<'a> = &'a str;
pub trait FromStrExt<'a> {
fn from_str(string: &'a str) -> Self;
}
impl<'a> FromStrExt<'a> for RStr<'a> {
fn from_str(string: &'a str) -> Self {
string }
}
pub type RHashMap<K, V, S = RandomState> = std::collections::HashMap<K, V, S>;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub struct Tuple2<A, B>(pub A, pub B);
pub mod map {
pub use std::collections::hash_map::Entry as REntry;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
#[repr(u8)]
pub enum ROption<T> {
RSome(T),
RNone,
}
use std::time::Duration;
pub use self::ROption::*;
#[allow(clippy::missing_const_for_fn)]
impl<T> ROption<T> {
#[inline]
pub const fn as_ref(&self) -> ROption<&T> {
match self {
RSome(v) => RSome(v),
RNone => RNone,
}
}
#[inline]
pub fn as_mut(&mut self) -> ROption<&mut T> {
match self {
RSome(v) => RSome(v),
RNone => RNone,
}
}
#[inline]
pub const fn is_some(&self) -> bool {
matches!(self, RSome { .. })
}
#[inline]
pub const fn is_none(&self) -> bool {
matches!(self, RNone { .. })
}
#[inline]
pub fn into_option(self) -> Option<T> {
match self {
RSome(v) => Option::Some(v),
RNone => Option::None,
}
}
#[inline]
pub fn unwrap(self) -> T {
self.into_option().unwrap()
}
#[inline]
pub fn unwrap_or(self, def: T) -> T {
match self {
RSome(x) => x,
RNone => def,
}
}
#[inline]
pub fn map<U, F>(self, f: F) -> ROption<U>
where
F: FnOnce(T) -> U,
{
match self {
RSome(x) => RSome(f(x)),
RNone => RNone,
}
}
}
impl<T> Default for ROption<T> {
fn default() -> Self {
RNone
}
}
impl<T> From<Option<T>> for ROption<T> {
fn from(opt: Option<T>) -> Self {
match opt {
Some(v) => RSome(v),
None => RNone,
}
}
}
impl<T> Into<Option<T>> for ROption<T> {
fn into(self) -> Option<T> {
match self {
RSome(v) => Some(v),
RNone => None,
}
}
}
}
#[cfg(target_arch = "wasm32")]
pub use std_types::*;
#[cfg(target_arch = "wasm32")]
pub trait StableAbi {}