rquickjs_core/
lib.rs

1//! # High-level bindings to QuickJS
2//!
3//! The `rquickjs` crate provides safe high-level bindings to the [QuickJS](https://bellard.org/quickjs/) JavaScript engine.
4//! This crate is heavily inspired by the [rlua](https://crates.io/crates/rlua) crate.
5
6#![allow(clippy::needless_lifetimes)]
7#![cfg_attr(feature = "doc-cfg", feature(doc_cfg))]
8
9pub(crate) use std::{result::Result as StdResult, string::String as StdString};
10
11mod js_lifetime;
12pub mod markers;
13mod persistent;
14mod result;
15mod safe_ref;
16mod util;
17mod value;
18pub(crate) use safe_ref::*;
19pub mod runtime;
20pub use runtime::Runtime;
21pub mod context;
22pub use context::{Context, Ctx};
23pub mod class;
24pub use class::Class;
25pub use js_lifetime::JsLifetime;
26pub use persistent::Persistent;
27pub use result::{CatchResultExt, CaughtError, CaughtResult, Error, Result, ThrowResultExt};
28pub use value::{
29    array, atom, convert, function, module, object, promise, Array, Atom, BigInt, CString, Coerced,
30    Exception, Filter, FromAtom, FromIteratorJs, FromJs, Function, IntoAtom, IntoJs, IteratorJs,
31    Module, Null, Object, Promise, String, Symbol, Type, Undefined, Value,
32};
33
34pub mod allocator;
35#[cfg(feature = "loader")]
36#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "loader")))]
37pub mod loader;
38
39#[cfg(feature = "futures")]
40#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "futures")))]
41pub use context::AsyncContext;
42#[cfg(feature = "multi-ctx")]
43pub use context::MultiWith;
44#[cfg(feature = "futures")]
45#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "futures")))]
46pub use runtime::AsyncRuntime;
47pub use value::{ArrayBuffer, TypedArray};
48
49//#[doc(hidden)]
50pub mod qjs {
51    //! Native low-level bindings
52    pub use rquickjs_sys::*;
53}
54
55#[cfg(feature = "phf")]
56#[doc(hidden)]
57pub mod phf {
58    pub use phf::*;
59}
60
61pub mod prelude {
62    //! A group of often used types.
63    #[cfg(feature = "multi-ctx")]
64    pub use crate::context::MultiWith;
65    pub use crate::{
66        context::Ctx,
67        convert::{Coerced, FromAtom, FromIteratorJs, FromJs, IntoAtom, IntoJs, IteratorJs, List},
68        function::{
69            Exhaustive, Flat, Func, FuncArg, IntoArg, IntoArgs, MutFn, OnceFn, Opt, Rest, This,
70        },
71        result::{CatchResultExt, ThrowResultExt},
72        JsLifetime,
73    };
74    #[cfg(feature = "futures")]
75    #[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "futures")))]
76    pub use crate::{
77        function::Async,
78        promise::{Promise, Promised},
79    };
80}
81
82#[cfg(test)]
83pub(crate) fn test_with<F, R>(func: F) -> R
84where
85    F: FnOnce(Ctx) -> R,
86{
87    let rt = Runtime::new().unwrap();
88    let ctx = Context::full(&rt).unwrap();
89    ctx.with(func)
90}
91
92mod deprecated_features {
93    #[cfg(feature = "properties")]
94    #[allow(unused_imports)]
95    use properties as _;
96    #[cfg(feature = "properties")]
97    #[deprecated(
98        note = "The rquickjs crate feature `properties` is deprecated, the functionality it provided is now enabled by default.
99To remove this warning remove the use of the feature when specifying the dependency."
100    )]
101    mod properties {}
102
103    #[cfg(feature = "array-buffer")]
104    #[allow(unused_imports)]
105    use array_buffer as _;
106    #[cfg(feature = "array-buffer")]
107    #[deprecated(
108        note = "The rquickjs crate feature `array-buffer` is deprecated, the functionality it provided is now enabled by default.
109To remove this warning remove the use of the feature when specifying the dependency."
110    )]
111    mod array_buffer {}
112
113    #[cfg(feature = "classes")]
114    #[allow(unused_imports)]
115    use classes as _;
116    #[cfg(feature = "classes")]
117    #[deprecated(
118        note = "The rquickjs crate feature `classes` is deprecated, the functionality it provided is now enabled by default.
119To remove this warning remove the use of the feature when specifying the dependency."
120    )]
121    mod classes {}
122
123    #[cfg(feature = "allocator")]
124    #[allow(unused_imports)]
125    use allocator as _;
126    #[cfg(feature = "allocator")]
127    #[deprecated(
128        note = "The rquickjs crate feature `allocator` is deprecated, the functionality it provided is now enabled by default.
129To remove this warning remove the use of the feature when specifying the dependency."
130    )]
131    mod allocator {}
132}