From 971581549bd537822b32957cc78fe0a26712415a Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Tue, 3 Feb 2026 23:47:30 +0000 Subject: [PATCH] Add no-std support Signed-off-by: Jorge Prendes --- Cargo.lock | 10 ---------- Cargo.toml | 4 ++-- src/de.rs | 5 ++++- src/err.rs | 6 ++++-- src/lib.rs | 4 ++++ src/ser.rs | 2 ++ src/utils.rs | 5 +++-- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 479acdb..07269f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,15 +170,6 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "relative-path" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca40a312222d8ba74837cb474edef44b37f561da5f773981007a10bbaa992b0" -dependencies = [ - "serde", -] - [[package]] name = "rquickjs" version = "0.11.0" @@ -195,7 +186,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8bf7840285c321c3ab20e752a9afb95548c75cd7f4632a0627cea3507e310c1" dependencies = [ "hashbrown", - "relative-path", "rquickjs-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 449c135..df084c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ readme = "README.md" authors = ["Emile Fugulin ", "The Javy Project Developers"] [dependencies] -rquickjs = "0.11" -serde = "1" +rquickjs = { version = "0.11", default-features = false } +serde = { version = "1", default-features = false, features = ["alloc"] } [dev-dependencies] quickcheck = "1" diff --git a/src/de.rs b/src/de.rs index 68a5c4e..85fce94 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1,3 +1,6 @@ +use alloc::string::{String, ToString as _}; +use alloc::vec::Vec; + use rquickjs::{ Exception, Filter, Function, Null, Object, String as JSString, Value, atom::PredefinedAtom, @@ -96,7 +99,7 @@ impl<'js> Deserializer<'js> { if let Some(f64_representation) = self.value.as_float() { let is_positive = f64_representation.is_sign_positive(); let safe_integer_range = (MIN_SAFE_INTEGER as f64)..=(MAX_SAFE_INTEGER as f64); - let whole = f64_representation.fract() == 0.0; + let whole = (f64_representation % 1.0) == 0.0; if whole && is_positive && f64_representation <= u32::MAX as f64 { return visitor.visit_u32(f64_representation as u32); diff --git a/src/err.rs b/src/err.rs index cb53aa2..e590fff 100644 --- a/src/err.rs +++ b/src/err.rs @@ -1,4 +1,6 @@ -use std::{error, fmt}; +use alloc::boxed::Box; +use alloc::string::{String, ToString as _}; +use core::{error, fmt}; use rquickjs::{Ctx, Error as JSError, Exception, Value}; use serde::{de, ser}; @@ -18,7 +20,7 @@ impl Error { } /// Alias for a `Result` with the error type `rquickjs_serde::Error`. -pub type Result = std::result::Result; +pub type Result = core::result::Result; impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/lib.rs b/src/lib.rs index bd3f305..6b0a78a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +#![cfg_attr(not(test), no_std)] + +extern crate alloc; + use rquickjs::{Ctx, Value}; use serde::Serialize; use serde::de::DeserializeOwned; diff --git a/src/ser.rs b/src/ser.rs index 024a224..19a1519 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -1,3 +1,5 @@ +use alloc::string::ToString as _; + use rquickjs::{Array, Ctx, Object, String as JSString, Value, object::Property}; use serde::{Serialize, ser}; diff --git a/src/utils.rs b/src/utils.rs index b7e9bc7..59d85bf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,5 @@ -use std::str; +use alloc::string::String; +use core::str; use rquickjs::{Ctx, Error as JSError, String as JSString, Value, qjs}; @@ -29,7 +30,7 @@ pub fn to_string_lossy<'js>(cx: &Ctx<'js>, string: &JSString<'js>, error: JSErro (false).into(), ) }; - let buffer = unsafe { std::slice::from_raw_parts(ptr as *const u8, len as usize) }; + let buffer = unsafe { core::slice::from_raw_parts(ptr as *const u8, len as usize) }; // The error here *must* be a Utf8 error; the `JSString::to_string()` may // return `JSError::Unknown`, but at that point, something else has gone