Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ documentation = "https://docs.rs/crate/pythonize/"
[dependencies]
serde = { version = "1.0", default-features = false, features = ["std"] }
pyo3 = { version = "0.27", default-features = false }
sonic-rs = "0.5.6"

[dev-dependencies]
serde = { version = "1.0", default-features = false, features = ["derive"] }
pyo3 = { version = "0.27", default-features = false, features = ["auto-initialize", "macros", "py-clone"] }
serde_json = "1.0"
serde_bytes = "0.11"
maplit = "1.0.2"
serde_path_to_error = "0.1.15"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is an experimental serializer for Rust's serde ecosystem, which can convert Rust objects to Python values and back.

At the moment the Python structures it produces should be _very_ similar to those which are produced by `serde_json`; i.e. calling Python's `json.loads()` on a value encoded by `serde_json` should produce an identical structure to
At the moment the Python structures it produces should be _very_ similar to those which are produced by `sonic_rs`; i.e. calling Python's `json.loads()` on a value encoded by `sonic_rs` should produce an identical structure to
that which is produced directly by `pythonize`.

## Usage
Expand Down
44 changes: 22 additions & 22 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ mod test {
use maplit::hashmap;
use pyo3::ffi::c_str;
use pyo3::{IntoPyObject, Python};
use serde_json::{json, Value as JsonValue};
use sonic_rs::{json, Value as JsonValue};

fn test_de<T>(code: &CStr, expected: &T, expected_json: &JsonValue)
where
Expand Down Expand Up @@ -826,26 +826,26 @@ mod test {
#[test]
fn test_int_limits() {
Python::attach(|py| {
// serde_json::Value supports u64 and i64 as maximum sizes
let _: serde_json::Value = depythonize(&u8::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&u8::MIN.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i8::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i8::MIN.into_pyobject(py).unwrap()).unwrap();

let _: serde_json::Value = depythonize(&u16::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&u16::MIN.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i16::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i16::MIN.into_pyobject(py).unwrap()).unwrap();

let _: serde_json::Value = depythonize(&u32::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&u32::MIN.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i32::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i32::MIN.into_pyobject(py).unwrap()).unwrap();

let _: serde_json::Value = depythonize(&u64::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&u64::MIN.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i64::MAX.into_pyobject(py).unwrap()).unwrap();
let _: serde_json::Value = depythonize(&i64::MIN.into_pyobject(py).unwrap()).unwrap();
// sonic_rs::Value supports u64 and i64 as maximum sizes
let _: sonic_rs::Value = depythonize(&u8::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&u8::MIN.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i8::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i8::MIN.into_pyobject(py).unwrap()).unwrap();

let _: sonic_rs::Value = depythonize(&u16::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&u16::MIN.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i16::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i16::MIN.into_pyobject(py).unwrap()).unwrap();

let _: sonic_rs::Value = depythonize(&u32::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&u32::MIN.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i32::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i32::MIN.into_pyobject(py).unwrap()).unwrap();

let _: sonic_rs::Value = depythonize(&u64::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&u64::MIN.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i64::MAX.into_pyobject(py).unwrap()).unwrap();
let _: sonic_rs::Value = depythonize(&i64::MIN.into_pyobject(py).unwrap()).unwrap();

let _: u128 = depythonize(&u128::MAX.into_pyobject(py).unwrap()).unwrap();
let _: i128 = depythonize(&u128::MIN.into_pyobject(py).unwrap()).unwrap();
Expand Down Expand Up @@ -882,7 +882,7 @@ mod test {
.unwrap()
.call0()
.unwrap();
let err = depythonize::<serde_json::Value>(&obj).unwrap_err();
let err = depythonize::<sonic_rs::Value>(&obj).unwrap_err();
assert!(matches!(
*err.inner,
ErrorImpl::UnsupportedType(name) if name == "Decimal"
Expand Down
2 changes: 1 addition & 1 deletion src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ mod test {
let result = result.extract::<PyBackedStr>()?;

assert_eq!(result, expected);
assert_eq!(serde_json::to_string(&src).unwrap(), expected);
assert_eq!(sonic_rs::to_string(&src).unwrap(), expected);

Ok(())
})
Expand Down
2 changes: 1 addition & 1 deletion tests/test_custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use pythonize::{
PythonizeNamedMappingType, PythonizeTypes, PythonizeUnnamedMappingAdapter, Pythonizer,
};
use serde::Serialize;
use serde_json::{json, Value};
use sonic_rs::{json, Value};

#[pyclass(sequence)]
struct CustomList {
Expand Down