| Crates.io | rquickjs-serde |
| lib.rs | rquickjs-serde |
| version | 0.1.0 |
| created_at | 2025-06-15 18:50:40.942601+00 |
| updated_at | 2025-06-15 18:50:40.942601+00 |
| description | Serde support for rquickjs |
| homepage | |
| repository | https://github.com/rquickjs/rquickjs-serde |
| max_upload_size | |
| id | 1713539 |
| size | 83,869 |
This is a serde serializer/deserializer for rquickjs Value.
use std::error::Error;
use serde::Serialize;
use rquickjs::{Runtime, Context};
#[derive(Serialize)]
struct User {
fingerprint: String,
location: String,
}
fn main() {
let rt = Runtime::new().unwrap();
let ctx = Context::full(&rt).unwrap();
// Serialize to a Value<'_>
let u = User {
fingerprint: "0xF9BA143B95FF6D82".to_owned(),
location: "Menlo Park, CA".to_owned(),
};
ctx.with(|ctx| {
let v = rquickjs_serde::to_value(ctx, u).unwrap();
let obj = v.into_object().unwrap();
let fingerprint: String = obj.get("fingerprint").unwrap();
assert_eq!(fingerprint, "0xF9BA143B95FF6D82");
let location: String = obj.get("location").unwrap();
assert_eq!(location, "Menlo Park, CA");
});
// Deserialize from a Value<'_>
let v = ctx.with(|ctx| {
ctx.eval::<Value<'_>, _>("var a = {fingerprint: '0xF9BA143B95FF6D82', location: 'Menlo Park, CA'};").unwrap();
let val = ctx.globals().get("a").unwrap();
let u: User = rquickjs_serde::from_value(val).unwrap();
u
});
assert_eq!(v.fingerprint, "0xF9BA143B95FF6D82");
assert_eq!(v.location, "Menlo Park, CA");
}
This project includes code derived from the Javy project. See NOTICE for more details.