Skip to content

Commit 891a4d4

Browse files
authored
Update to edition 2024, MSRV 1.88 (#243)
1 parent b14af5e commit 891a4d4

14 files changed

Lines changed: 121 additions & 120 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ resolver = "2"
66
[workspace.package]
77
authors = ["Samuel Colvin <samuel@pydantic.dev>"]
88
version = "0.13.0"
9-
edition = "2021"
9+
edition = "2024"
1010
license = "MIT"
1111
keywords = ["JSON", "parsing", "deserialization", "iter"]
1212
categories = ["parser-implementations", "parsing"]
1313
homepage = "https://github.com/pydantic/jiter/"
1414
repository = "https://github.com/pydantic/jiter/"
1515
# MSRV should match pydantic-core
16-
rust-version = "1.83"
16+
rust-version = "1.88"
1717

1818
[profile.bench]
1919
debug = true

crates/jiter-python/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn get_jiter_version() -> &'static str {
1919
mod jiter_python {
2020
use pyo3::prelude::*;
2121

22-
use jiter::{map_json_error, FloatMode, LosslessFloat, PartialMode, PythonParse, StringCacheMode};
22+
use jiter::{FloatMode, LosslessFloat, PartialMode, PythonParse, StringCacheMode, map_json_error};
2323

2424
use super::get_jiter_version;
2525

crates/jiter/benches/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
1+
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
22

33
use std::fs::File;
44
use std::hint::black_box;

crates/jiter/benches/python.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
1+
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
22

33
use std::fs::File;
44
use std::io::Read;
55
use std::path::Path;
66

77
use pyo3::Python;
88

9-
use jiter::{cache_clear, PythonParse, StringCacheMode};
9+
use jiter::{PythonParse, StringCacheMode, cache_clear};
1010

1111
fn python_parse_numeric(c: &mut Criterion) {
1212
Python::attach(|py| {

crates/jiter/src/jiter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::errors::{json_error, JiterError, JsonType, LinePosition, DEFAULT_RECURSION_LIMIT};
1+
use crate::errors::{DEFAULT_RECURSION_LIMIT, JiterError, JsonType, LinePosition, json_error};
22
use crate::number_decoder::{NumberAny, NumberFloat, NumberInt, NumberRange};
33
use crate::parse::{Parser, Peek};
44
use crate::string_decoder::{StringDecoder, StringDecoderRange, Tape};
5-
use crate::value::{take_value_borrowed, take_value_owned, take_value_skip, JsonValue};
5+
use crate::value::{JsonValue, take_value_borrowed, take_value_owned, take_value_skip};
66
use crate::{JsonError, JsonErrorType, PartialMode};
77

88
pub type JiterResult<T> = Result<T, JiterError>;

crates/jiter/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ pub use value::{JsonArray, JsonObject, JsonValue};
173173
pub use py_lossless_float::{FloatMode, LosslessFloat};
174174
#[cfg(feature = "python")]
175175
pub use py_string_cache::{
176-
cache_clear, cache_usage, cached_py_string, cached_py_string_ascii, pystring_ascii_new, StringCacheMode,
176+
StringCacheMode, cache_clear, cache_usage, cached_py_string, cached_py_string_ascii, pystring_ascii_new,
177177
};
178178
#[cfg(feature = "python")]
179-
pub use python::{map_json_error, PythonParse};
179+
pub use python::{PythonParse, map_json_error};
180180

181181
#[derive(Debug, Clone, Copy, Default)]
182182
pub enum PartialMode {
@@ -188,11 +188,7 @@ pub enum PartialMode {
188188

189189
impl From<bool> for PartialMode {
190190
fn from(mode: bool) -> Self {
191-
if mode {
192-
Self::On
193-
} else {
194-
Self::Off
195-
}
191+
if mode { Self::On } else { Self::Off }
196192
}
197193
}
198194

crates/jiter/src/number_decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use pyo3::{IntoPyObject, IntoPyObjectRef};
77

88
use std::ops::Range;
99

10-
use lexical_parse_float::{format as lexical_format, FromLexicalWithOptions, Options as ParseFloatOptions};
10+
use lexical_parse_float::{FromLexicalWithOptions, Options as ParseFloatOptions, format as lexical_format};
1111

12-
use crate::errors::{json_err, json_error, JsonError, JsonResult};
12+
use crate::errors::{JsonError, JsonResult, json_err, json_error};
1313

1414
pub trait AbstractNumberDecoder {
1515
type Output;
@@ -483,7 +483,7 @@ impl AbstractNumberDecoder for NumberRange {
483483
let end = consume_exponential(data, index)?;
484484
Ok((Self::float(start..end), end))
485485
}
486-
}
486+
};
487487
}
488488
}
489489
}

crates/jiter/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22
use std::ops::Range;
33

4-
use crate::errors::{json_err, JsonResult, LinePosition};
4+
use crate::errors::{JsonResult, LinePosition, json_err};
55
use crate::number_decoder::AbstractNumberDecoder;
66
use crate::string_decoder::{AbstractStringDecoder, Tape};
77

crates/jiter/src/py_string_cache.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ impl<'py> FromPyObject<'_, 'py> for StringCacheMode {
4040

4141
impl From<bool> for StringCacheMode {
4242
fn from(mode: bool) -> Self {
43-
if mode {
44-
Self::All
45-
} else {
46-
Self::None
47-
}
43+
if mode { Self::All } else { Self::None }
4844
}
4945
}
5046

@@ -131,11 +127,13 @@ pub unsafe fn cached_py_string_ascii<'py>(py: Python<'py>, s: &str) -> Bound<'py
131127
///
132128
/// Caller must match the ascii_only flag to the string passed in.
133129
unsafe fn cached_py_string_maybe_ascii<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bound<'py, PyString> {
134-
// from tests, 0 and 1 character strings are faster not cached
135-
if (2..64).contains(&s.len()) {
136-
get_string_cache().get_or_insert(py, s, ascii_only)
137-
} else {
138-
pystring_fast_new_maybe_ascii(py, s, ascii_only)
130+
unsafe {
131+
// from tests, 0 and 1 character strings are faster not cached
132+
if (2..64).contains(&s.len()) {
133+
get_string_cache().get_or_insert(py, s, ascii_only)
134+
} else {
135+
pystring_fast_new_maybe_ascii(py, s, ascii_only)
136+
}
139137
}
140138
}
141139

@@ -254,19 +252,21 @@ unsafe fn pystring_fast_new_maybe_ascii<'py>(py: Python<'py>, s: &str, ascii_onl
254252
///
255253
/// `s` must be ASCII only
256254
pub unsafe fn pystring_ascii_new<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> {
257-
#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
258-
{
259-
let ptr = pyo3::ffi::PyUnicode_New(s.len() as isize, 127);
260-
// see https://github.com/pydantic/jiter/pull/72#discussion_r1545485907
261-
debug_assert_eq!(pyo3::ffi::PyUnicode_KIND(ptr), pyo3::ffi::PyUnicode_1BYTE_KIND);
262-
let data_ptr = pyo3::ffi::PyUnicode_DATA(ptr).cast();
263-
core::ptr::copy_nonoverlapping(s.as_ptr(), data_ptr, s.len());
264-
core::ptr::write(data_ptr.add(s.len()), 0);
265-
Bound::from_owned_ptr(py, ptr).cast_into_unchecked()
266-
}
255+
unsafe {
256+
#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
257+
{
258+
let ptr = pyo3::ffi::PyUnicode_New(s.len() as isize, 127);
259+
// see https://github.com/pydantic/jiter/pull/72#discussion_r1545485907
260+
debug_assert_eq!(pyo3::ffi::PyUnicode_KIND(ptr), pyo3::ffi::PyUnicode_1BYTE_KIND);
261+
let data_ptr = pyo3::ffi::PyUnicode_DATA(ptr).cast();
262+
core::ptr::copy_nonoverlapping(s.as_ptr(), data_ptr, s.len());
263+
core::ptr::write(data_ptr.add(s.len()), 0);
264+
Bound::from_owned_ptr(py, ptr).cast_into_unchecked()
265+
}
267266

268-
#[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
269-
{
270-
PyString::new(py, s)
267+
#[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
268+
{
269+
PyString::new(py, s)
270+
}
271271
}
272272
}

crates/jiter/src/python.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use pyo3::types::{PyBool, PyDict, PyList, PyString};
88

99
use smallvec::SmallVec;
1010

11-
use crate::errors::{json_err, json_error, JsonError, JsonResult, DEFAULT_RECURSION_LIMIT};
11+
use crate::errors::{DEFAULT_RECURSION_LIMIT, JsonError, JsonResult, json_err, json_error};
1212
use crate::number_decoder::{AbstractNumberDecoder, NumberAny, NumberRange};
1313
use crate::parse::{Parser, Peek};
14-
use crate::py_lossless_float::{get_decimal_type, FloatMode};
14+
use crate::py_lossless_float::{FloatMode, get_decimal_type};
1515
use crate::py_string_cache::{StringCacheAll, StringCacheKeys, StringCacheMode, StringMaybeCache, StringNoCache};
1616
use crate::string_decoder::{StringDecoder, Tape};
1717
use crate::{JsonErrorType, LosslessFloat, PartialMode};
@@ -148,10 +148,10 @@ impl<StringCache: StringMaybeCache, KeyCheck: MaybeKeyCheck, ParseNumber: MaybeP
148148
};
149149

150150
let mut vec: SmallVec<[Bound<'_, PyAny>; 8]> = SmallVec::with_capacity(8);
151-
if let Err(e) = self.parse_array(py, peek_first, &mut vec) {
152-
if !self.allow_partial_err(&e) {
153-
return Err(e);
154-
}
151+
if let Err(e) = self.parse_array(py, peek_first, &mut vec)
152+
&& !self.allow_partial_err(&e)
153+
{
154+
return Err(e);
155155
}
156156

157157
Ok(PyList::new(py, vec)
@@ -160,10 +160,10 @@ impl<StringCache: StringMaybeCache, KeyCheck: MaybeKeyCheck, ParseNumber: MaybeP
160160
}
161161
Peek::Object => {
162162
let dict = PyDict::new(py);
163-
if let Err(e) = self.parse_object(py, &dict) {
164-
if !self.allow_partial_err(&e) {
165-
return Err(e);
166-
}
163+
if let Err(e) = self.parse_object(py, &dict)
164+
&& !self.allow_partial_err(&e)
165+
{
166+
return Err(e);
167167
}
168168
Ok(dict.into_any())
169169
}

0 commit comments

Comments
 (0)