Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to doc formatting and linking. #233

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["QuickJS", ".."]
2 changes: 1 addition & 1 deletion core/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use trace::{Trace, Tracer};
#[doc(hidden)]
pub mod impl_;

/// The trait which allows rust types to be used from javascript.
/// The trait which allows Rust types to be used from JavaScript.
pub trait JsClass<'js>: Trace<'js> {
/// The name the constructor has in JavaScript
const NAME: &'static str;
Expand Down
2 changes: 1 addition & 1 deletion core/src/class/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub struct JsCell<'js, T: JsClass<'js>> {
}

impl<'js, T: JsClass<'js>> JsCell<'js, T> {
/// Create a new JsCell
/// Create a new `JsCell`
pub fn new(t: T) -> Self {
JsCell {
cell: <T::Mutable as Mutability>::new_cell(t),
Expand Down
18 changes: 9 additions & 9 deletions core/src/class/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ impl<T> ConstructorCreate<T> {
/// We would need this default implementation because it is not possible to know in class macro if
/// the method macro is triggered for a impl body of the same class.
///
/// We can get around this by using a bit of a heck called autoref-specialization.
/// We can get around this by using a bit of a hack called autoref-specialization.
///
/// MethodImplementor is implemented for a borrowed value generic over any T;
/// [`MethodImplementor`] is implemented for a borrowed value generic over any `T`;
/// This means you will always be able to call `(&&MethodImpl<T>).implement(proto)` because it is
/// implemented for all &MethodImpl<T>.
/// implemented for all `&MethodImpl<T>`.
///
/// However it the trait is also implemented for MethodImpl<Foo> for some specific class Foo the
/// However it the trait is also implemented for `MethodImpl<Foo>` for some specific class `Foo` the
/// compiler will automatically deref the first reference and call the method for the type
/// MethodImpl<Foo> instead of the general on.
/// `MethodImpl<Foo>` instead of the general on.
///
/// This allows us to provide a default implementation if no implementation of MethodImplementor is
/// present for T.
/// This allows us to provide a default implementation if no implementation of [`MethodImplementor`] is
/// present for `T`.
///
/// Originally described by dtolnay
impl<T> MethodImplementor<T> for &MethodImpl<T> {}

impl<'js, T> ConstructorCreator<'js, T> for &ConstructorCreate<T> {}

/// A helper struct to implement FromJs for types which implement clone.
/// A helper struct to implement [`FromJs`](crate::FromJs) for types which implement [`Clone`].
pub struct CloneWrapper<'a, T>(pub &'a T);
/// A helper trait to implement FromJs for types which implement clone.
/// A helper trait to implement [`FromJs`](crate::FromJs) for types which implement [`Clone`].
pub trait CloneTrait<T> {
fn wrap_clone(&self) -> T;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/class/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl<'a, 'js> Tracer<'a, 'js> {
/// Create a tracer from the c implementation.
///
/// # Safety
/// Caller must ensure that the trace doesn't outlive the lifetime of the mark_func and rt
/// pointer
/// Caller must ensure that the trace doesn't outlive the lifetime of the `mark_func` and
/// `rt` pointer
pub unsafe fn from_ffi(rt: *mut qjs::JSRuntime, mark_func: qjs::JS_MarkFunc) -> Self {
Self {
rt,
Expand Down
2 changes: 1 addition & 1 deletion core/src/context/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl<'js> Ctx<'js> {

/// Parse json into a JavaScript value, possibly allowing extended syntax support.
///
/// If allow_extensions is true, this function will allow extended json syntax.
/// If `allow_extensions` is `true`, this function will allow extended json syntax.
/// Extended syntax allows comments, single quoted strings, non string property names, trailing
/// comma's and hex, oct and binary numbers.
pub fn json_parse_ext<S>(&self, json: S, allow_extensions: bool) -> Result<Value<'js>>
Expand Down
10 changes: 5 additions & 5 deletions core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl Error {
matches!(self, Self::TooManyArgs { .. } | Self::MissingArgs { .. })
}

/// Optimized conversion to CString
/// Optimized conversion to [`CString`]
pub(crate) fn to_cstring(&self) -> CString {
// stringify error with NUL at end
let mut message = format!("{self}\0").into_bytes();
Expand Down Expand Up @@ -646,11 +646,11 @@ impl<'js> Ctx<'js> {
}
}

/// Handle possible exceptions in JSValue's and turn them into errors
/// Will return the JSValue if it is not an exception
/// Handle possible exceptions in [`JSValue`]'s and turn them into errors
/// Will return the [`JSValue`] if it is not an exception
///
/// # Safety
/// Assumes to have ownership of the JSValue
/// Assumes to have ownership of the [`JSValue`]
pub(crate) unsafe fn handle_exception(&self, js_val: qjs::JSValue) -> Result<qjs::JSValue> {
if qjs::JS_VALUE_GET_NORM_TAG(js_val) != qjs::JS_TAG_EXCEPTION {
Ok(js_val)
Expand All @@ -662,7 +662,7 @@ impl<'js> Ctx<'js> {
}
}

/// Returns Error::Exception if there is no existing panic,
/// Returns [`Error::Exception`] if there is no existing panic,
/// otherwise continues panicking.
pub(crate) fn raise_exception(&self) -> Error {
// Safety
Expand Down
2 changes: 1 addition & 1 deletion core/src/runtime/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::qjs;
use super::spawner::Spawner;
use super::InterruptHandler;

/// Opaque book keeping data for rust.
/// Opaque book keeping data for Rust.
pub(crate) struct Opaque<'js> {
/// Used to carry a panic if a callback triggered one.
pub panic: Option<Box<dyn Any + Send + 'static>>,
Expand Down
2 changes: 1 addition & 1 deletion core/src/value/convert/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
T: FromJs<'js>,
{
// TODO this function seems a bit hacky.
// Expections are generally by the marshalling handled when returned callback.
// Exceptions are generally by the marshalling handled when returned callback.
fn from_js(ctx: &Ctx<'js>, value: Value<'js>) -> Result<Self> {
unsafe {
match ctx.handle_exception(value.into_js_value()) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/value/function/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl StaticJsFn {
}
}

/// A trait for dynamic callbacks to rust.
/// A trait for dynamic callbacks to Rust.
pub trait RustFunc<'js> {
/// Call the actual function with a given set of parameters and return a function.
fn call<'a>(&self, params: Params<'a, 'js>) -> Result<Value<'js>>;
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'js> JsClass<'js> for RustFunction<'js> {
}

mod mac {
/// A macro for implementing StaticJsFunction for generic functions.
/// A macro for implementing [`StaticJsFunction`](crate::function::StaticJsFunction) for generic functions.
#[macro_export]
macro_rules! static_fn {
($f:ident) => {{
Expand Down
12 changes: 6 additions & 6 deletions core/src/value/function/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Ctx, Function, IntoJs, Result, Value};

use super::IntoJsFunc;

/// Helper type to implement ToJsFunction for closure by constraining arguments.
/// Helper type to implement [`IntoJsFunc`] for closure by constraining arguments.
pub struct Func<T, P>(T, PhantomData<P>);

impl<'js, T, P> Func<T, P>
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct This<T>(pub T);
/// helper type for retrieving function object on which a function is called..
pub struct FuncArg<T>(pub T);

/// Helper type for optional paramaters.
/// Helper type for optional parameters.
pub struct Opt<T>(pub Option<T>);

/// Helper type for rest and spread arguments.
Expand All @@ -57,8 +57,8 @@ pub struct Null<T>(pub Option<T>);
/// A type to flatten tuples into another tuple.
///
/// ToArgs is only implemented for tuples with a length of up to 8.
/// If you need more arguments you can use this type to extend arguments with upto 8 additional
/// arguments recursivily.
/// If you need more arguments you can use this type to extend arguments with up to 8 additional
/// arguments recursively.
pub struct Flat<T>(pub T);

/// Helper type for making an parameter set exhaustive.
Expand All @@ -67,7 +67,7 @@ pub struct Exhaustive;
/// Helper type for creating a function from a closure which returns a future.
pub struct Async<T>(pub T);

/// Helper type for creating a function from a closure which implements FnMut
/// Helper type for creating a function from a closure which implements [`FnMut`]
///
/// When called will try to borrow the internal [`RefCell`], if this is not
/// possible it will return an error.
Expand All @@ -85,7 +85,7 @@ impl<T> From<T> for MutFn<T> {
}
}

/// Helper type for creating a function from a closure which implements FnMut
/// Helper type for creating a function from a closure which implements [`FnMut`]
///
/// When called, will take the internal value leaving it empty. If the internal
/// value was already empty it will return a error.
Expand Down
6 changes: 3 additions & 3 deletions core/src/value/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub type ModuleLoadFn =
pub enum ModuleDataKind {
/// Module source text,
Source(Vec<u8>),
/// A function which loads a module from rust.
/// A function which loads a module from Rust.
Native(for<'js> unsafe fn(ctx: &Ctx<'js>, name: Vec<u8>) -> Result<Module<'js>>),
/// A raw loading function, used for loading from dynamic libraries.
Raw(ModuleLoadFn),
Expand Down Expand Up @@ -153,7 +153,7 @@ impl ModuleData {
/// Create module data for a module loaded from a native Rust definition.
///
/// # Safety
/// User must ensure that load_fn behaves like a loader function.
/// User must ensure that `load_fn` behaves like a loader function.
///
/// The function must take a context and a c string without taking ownership of either values
/// and return a pointer to `qjs::JSModuleDef`, or a null pointer if there was some error.
Expand Down Expand Up @@ -297,7 +297,7 @@ impl Declarations {
Ok(self)
}

/// Define a new export in a module using a static CStr.
/// Define a new export in a module using a static `CStr`.
///
/// This method is can be used to avoid some allocation in the case that the name is static.
pub fn declare_static(&mut self, name: &'static CStr) -> Result<&mut Self> {
Expand Down
2 changes: 1 addition & 1 deletion macro/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl FunctionConfig {
)
}

/// The name for the javascript side
/// The name for the JavaScript side
pub fn js_name(&self, rust_name: &Ident, case: Option<Case>) -> String {
if let Some(x) = self.rename.as_ref() {
return x.clone();
Expand Down
24 changes: 12 additions & 12 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod methods;
mod module;
mod trace;

/// An attribute for implementing [`JsClass`](rquickjs_core::class::JsClass`) for a rust type.
/// An attribute for implementing [`JsClass`](rquickjs_core::class::JsClass`) for a Rust type.
///
/// # Attribute options
///
Expand Down Expand Up @@ -63,15 +63,15 @@ mod trace;
/// use rquickjs::{class::Trace, CatchResultExt, Class, Context, Object, Runtime};
///
/// /// Implement JsClass for TestClass.
/// /// This allows passing any instance of TestClass straight to javascript.
/// /// This allows passing any instance of TestClass straight to JavaScript.
/// /// It is command to also add #[derive(Trace)] as all types which implement JsClass need to
/// /// also implement trace.
/// #[derive(Trace)]
/// #[rquickjs::class(rename_all = "camelCase")]
/// pub struct TestClass<'js> {
/// /// These attribute make the accessible from javascript with getters and setters.
/// /// These attribute make the accessible from JavaScript with getters and setters.
/// /// As we used `rename_all = "camelCase"` in the attribute it will be called `innerObject`
/// /// on the javascript side.
/// /// on the JavaScript side.
/// #[qjs(get, set)]
/// inner_object: Object<'js>,
///
Expand All @@ -98,7 +98,7 @@ mod trace;
/// },
/// )
/// .unwrap();
/// /// Pass it to javascript
/// /// Pass it to JavaScript
/// ctx.globals().set("t", cls.clone()).unwrap();
/// ctx.eval::<(), _>(
/// r#"
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn function(attr: TokenStream1, item: TokenStream1) -> TokenStream1 {
/// [`macro@class`] attribute to derive [`JsClass`](rquickjs_core::class::JsClass).
///
/// # Limitations
/// Due to limitations in the rust type system this attribute can be used on only one impl block
/// Due to limitations in the Rust type system this attribute can be used on only one impl block
/// per type.
///
/// # Attribute options
Expand Down Expand Up @@ -243,7 +243,7 @@ pub fn function(attr: TokenStream1, item: TokenStream1) -> TokenStream1 {
/// #[qjs(skip)]
/// pub fn inner_function(&self) {}
///
/// /// Functions can also be renamed to specific symbols. This allows you to make an rust type
/// /// Functions can also be renamed to specific symbols. This allows you to make an Rust type
/// /// act like an iteratable value for example.
/// #[qjs(rename = PredefinedAtom::SymbolIterator)]
/// pub fn iterate<'js>(&self, ctx: Ctx<'js>) -> Result<Object<'js>> {
Expand Down Expand Up @@ -292,7 +292,7 @@ pub fn methods(attr: TokenStream1, item: TokenStream1) -> TokenStream1 {
}
}

/// An attribute which generates code for exporting a module to rust.
/// An attribute which generates code for exporting a module to Rust.
///
/// Any supported item inside the module which is marked as `pub` will be exported as a JavaScript value.
/// Different items result in different JavaScript values.
Expand Down Expand Up @@ -320,7 +320,7 @@ pub fn methods(attr: TokenStream1, item: TokenStream1) -> TokenStream1 {
/// | `rename` | String | Changes the name of the implemented module on the JavaScript side. |
/// | `rename_vars` | Casing | Alters the name of all items exported as JavaScript values by changing the case. Can be one of `lowercase`, `UPPERCASE`, `camelCase`, `PascalCase`,`snake_case`, or `SCREAMING_SNAKE` |
/// | `rename_types` | Casing | Alters the name of all items exported as JavaScript classes by changing the case. Can be one of `lowercase`, `UPPERCASE`, `camelCase`, `PascalCase`,`snake_case`, or `SCREAMING_SNAKE` |
/// | `prefix` | String | The module will be implemented for a new type with roughly the same name as the rust module with a prefix added. This changes the prefix which will be added. Defaults to `js_` |
/// | `prefix` | String | The module will be implemented for a new type with roughly the same name as the Rust module with a prefix added. This changes the prefix which will be added. Defaults to `js_` |
///
/// # Item options
///
Expand Down Expand Up @@ -426,7 +426,7 @@ pub fn methods(attr: TokenStream1, item: TokenStream1) -> TokenStream1 {
/// 1 + 1
/// }
///
/// /// You can make items public but not export them to javascript by adding the skip attribute.
/// /// You can make items public but not export them to JavaScript by adding the skip attribute.
/// #[qjs(skip)]
/// pub fn ignore_function() -> u32 {
/// 2 + 2
Expand Down Expand Up @@ -480,9 +480,9 @@ pub fn trace(stream: TokenStream1) -> TokenStream1 {
trace::expand(derive_input).into()
}

/// A macro for embedding javascript code into a binary.
/// A macro for embedding JavaScript code into a binary.
///
/// Compiles a javascript module to bytecode and then compiles the resulting bytecode into the
/// Compiles a JavaScript module to bytecode and then compiles the resulting bytecode into the
/// binary. Each file loaded is turned into its own module. The macro takes a list of paths to
/// files to be compiled into a module with an option name. Module paths are relative to the crate
/// manifest file.
Expand Down
2 changes: 1 addition & 1 deletion macro/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn export_use(use_: &UseTree, module: &mut JsModule, config: &ModuleItemConfig)
}
UseTree::Glob(x) => {
emit_warning!(
x.star_token,"Using a glob export does not export the items to javascript";
x.star_token,"Using a glob export does not export the items to JavaScript";
note = "Please specify each item to be exported individially."
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! environment. Contexts of the same runtime can share JavaScript objects like in the browser between
//! frames of the same origin.
//!
//! As both [`Runtime`] and [`Context`] use a lock it is discourged to use them in a async
//! As both [`Runtime`] and [`Context`] use a lock it is discouraged to use them in a async
//! environment. Instead, when the `futures` feature is enabled this library also exposes
//! [`AsyncRuntime`] and [`AsyncContext`] which use a future aware lock.
//!
Expand Down Expand Up @@ -62,7 +62,7 @@
//! - `futures` adds support for async Rust. When enabled the library exports [`AsyncRuntime`] and
//! [`AsyncContext`]. These are the asynchronous variants of the normal runtime and context. In
//! order to ensure that QuickJS is used properly the runtime is placed behind a lock. For the
//! normal runtime this is a normal mutex. You should avoid blocking threads in asynchronous rust
//! normal runtime this is a normal mutex. You should avoid blocking threads in asynchronous Rust
//! so the async runtime uses a future aware mutex. In the async runtime Rust futures can be passed
//! to JS as [ES6
//! Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
Expand Down
2 changes: 1 addition & 1 deletion sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn patch<D: AsRef<Path>, P: AsRef<Path>>(out_dir: D, patch: P) {
.current_dir(out_dir)
.spawn()
.expect("Unable to execute patch, you may need to install it: {}");
println!("Appliyng patch {}", patch.as_ref().display());
println!("Applying patch {}", patch.as_ref().display());
{
let patch = fs::read(patch).expect("Unable to read patch");

Expand Down
4 changes: 2 additions & 2 deletions sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use std::ptr;

/// Common error message for converting between c 'size_t' and Rust 'usize';
pub const SIZE_T_ERROR: &str = "c type 'size_t' did not fit into Rust type 'usize'";
/// Common error message for converting between C `size_t` and Rust `usize`;
pub const SIZE_T_ERROR: &str = "C type 'size_t' did not fit into Rust type 'usize'";

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

Expand Down
2 changes: 1 addition & 1 deletion tests/macros/pass_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod test_mod {
1 + 1
}

/// You can make items public but not export them to javascript by adding the skip attribute.
/// You can make items public but not export them to JavaScript by adding the skip attribute.
#[qjs(skip)]
pub fn ignore_function() -> u32 {
2 + 2
Expand Down