use crate::{__doc_show, _js_safe_ffi, _js_unsafe_ffi, js_number, macro_apply};
pub(crate) struct JsNumFmt<const P: usize>(pub js_number);
impl<const P: usize> core::fmt::Debug for JsNumFmt<P> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:.*}", P, self.0)
}
}
#[rustfmt::skip]
macro_rules! _js_doc {
( // Link to an API Object
$API:literal) => { concat)"] };
( // Link to a method of an API Object
$API:literal, $method:literal) => { concat)"] };
(canvas $method:literal) => { concat)"] };
(console $method:literal) => { concat)"] };
}
pub(crate) use _js_doc;
#[rustfmt::skip]
#[macro_apply(_js_unsafe_ffi)]
macro_rules! _js_extern {
(
// # Args
// [ header section
// $module: optional js module name (defaults to "env")
[ $(module: $module:literal)? $(,)? ]
$(
$(#[$fn_attrs:meta])*
$vis:vis $(safe$($_s:block)?)? $(unsafe$($_u:block)?)?
fn
$($js_fn:literal)?
$fn:ident
($($param:ident: $param_ty:ty),* $(,)?) $(-> $fn_return:ty)?;
)*
) => {
$( #[link(wasm_import_module = $module)] )?
#[cfg(not(feature = "safe_lang"))]
unsafe extern "C" { $(
$(#[$fn_attrs])*
$( #[link_name = $js_fn] )?
$vis $(safe$($_s)?)? $(unsafe$($_u)?)?
fn $fn($($param: $param_ty),*) $(-> $fn_return)?;
)* }
};
}
#[rustfmt::skip]
#[macro_apply(_js_safe_ffi)]
macro_rules! _js_extern { ($($tt:tt)*) => {}; }
#[macro_apply(__doc_show(feature = "unsafe_ffi"))]
pub(crate) use _js_extern;
#[rustfmt::skip]
macro_rules! _js_method_str_alloc {
(
$(#[$fn_attrs:meta])*
$method_name:ident,
$call_fn:ident $(,)?
) => { $crate::paste! {
$(#[$fn_attrs])*
pub fn $method_name(buffer: &mut [u8]) -> &str {
$crate::Js::read_str(buffer, |ptr, len| unsafe { $call_fn(ptr, len) })
}
$(#[$fn_attrs])*
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
pub fn [<$method_name _alloc>]() -> $crate::String {
$crate::Js::read_string(|ptr, len| unsafe { $call_fn(ptr, len) })
}
}};
}
#[allow(unused_imports, reason = "WIP JsObject")]
pub(crate) use _js_method_str_alloc;