Skip to content

Commit 28195cc

Browse files
committed
Target abi3-py310 and use to_str for single-copy string extraction
1 parent d55ddd0 commit 28195cc

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
- Use the existing `saphyr`/`saphyr-parser` git dependencies; do not change crate sources or pins without approval.
1212
- For Python bindings, preserve the exposed API (`parse_yaml`, `read_yaml`, `format_yaml`, `write_yaml`) and the `Tagged` dataclass contract. Tagged values wrap non-core tags only; canonical/core tags are treated as untagged.
1313
- Keep conversions zero-copy where practical and prefer borrowing (`&str`, slices) over allocating new `String`s when possible.
14+
- Performance is the top priority; if a measurable speedup requires hairy or off-contract techniques, prefer the faster approach and document the choice.
1415
- When running checks, use `cargo check` or `cargo test` from the project root; avoid adding new test frameworks without approval. Use `cargo fmt` before final delivery if Rust code changed.
1516
- Before wrapping up, always run: `cargo fmt`, `cargo check`, `cargo test`, `cargo build`, `cargo clippy`, `.venv/bin/pip install -e . --no-build-isolation`, and `.venv/bin/python -m pytest tests_py`.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "yaml12"
99
crate-type = ["cdylib", "rlib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.25.0", features = ["extension-module", "abi3-py38"] }
12+
pyo3 = { version = "0.25.0", features = ["extension-module", "abi3-py310"] }
1313
saphyr = { git = "https://github.com/t-kalinowski/saphyr", branch = "r-patched" }
1414
saphyr-parser = { git = "https://github.com/t-kalinowski/saphyr", branch = "r-patched" }
1515

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ build-backend = "maturin"
44

55
[project]
66
name = "yaml12"
7-
requires-python = ">=3.8"
7+
requires-python = ">=3.10"
88
classifiers = [
99
"Programming Language :: Rust",
1010
"Programming Language :: Python :: Implementation :: CPython",
1111
"Programming Language :: Python :: Implementation :: PyPy",
1212
]
1313
dynamic = ["version"]
1414
[tool.maturin]
15-
features = ["pyo3/extension-module", "pyo3/abi3-py38"]
15+
features = ["pyo3/extension-module", "pyo3/abi3-py310"]

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl HandlerRegistry {
131131
let key_str = key_obj.downcast::<PyString>().map_err(|_| {
132132
PyTypeError::new_err("handler keys must be strings or subclasses of str")
133133
})?;
134-
let key_text = key_str.to_cow()?;
135-
let key = parse_handler_name(key_text.as_ref())?;
134+
let key_text = key_str.to_str()?;
135+
let key = parse_handler_name(key_text)?;
136136
if !value_obj.is_callable() {
137137
return Err(PyTypeError::new_err(format!(
138138
"handler `{}` must be callable",
@@ -156,8 +156,8 @@ impl HandlerRegistry {
156156
let key_str = key_obj.downcast::<PyString>().map_err(|_| {
157157
PyTypeError::new_err("handler keys must be strings or subclasses of str")
158158
})?;
159-
let key_text = key_str.to_cow()?;
160-
let key = parse_handler_name(key_text.as_ref())?;
159+
let key_text = key_str.to_str()?;
160+
let key = parse_handler_name(key_text)?;
161161
if !value_obj.is_callable() {
162162
return Err(PyTypeError::new_err(format!(
163163
"handler `{}` must be callable",
@@ -393,7 +393,7 @@ fn write_yaml(py: Python<'_>, value: PyObject, path: Option<&str>, multi: bool)
393393

394394
fn join_text(text: &Bound<'_, PyAny>) -> Result<Option<String>> {
395395
if let Ok(s) = text.downcast::<PyString>() {
396-
return Ok(Some(s.to_cow()?.into_owned()));
396+
return Ok(Some(s.to_str()?.to_owned()));
397397
}
398398

399399
if let Ok(seq) = text.downcast::<PySequence>() {
@@ -407,7 +407,7 @@ fn join_text(text: &Bound<'_, PyAny>) -> Result<Option<String>> {
407407
let s = item.downcast::<PyString>().map_err(|_| {
408408
PyTypeError::new_err("`text` sequence must contain only strings without None")
409409
})?;
410-
parts.push(s.to_cow()?.into_owned());
410+
parts.push(s.to_str()?.to_owned());
411411
}
412412
return Ok(Some(parts.join("\n")));
413413
}
@@ -760,15 +760,15 @@ fn py_to_yaml(py: Python<'_>, obj: &Bound<'_, PyAny>, is_key: bool) -> Result<Ya
760760

761761
if let Ok(s) = obj.downcast::<PyString>() {
762762
return Ok(Yaml::Value(Scalar::String(Cow::Owned(
763-
s.to_cow()?.into_owned(),
763+
s.to_str()?.to_owned(),
764764
))));
765765
}
766766

767767
if is_tagged(py, obj)? {
768768
let value_obj = obj.getattr("value")?;
769769
let tag_obj = obj.getattr("tag")?;
770-
let tag_str = tag_obj.downcast::<PyString>()?.to_cow()?;
771-
let tag = parse_tag_string(tag_str.as_ref())?;
770+
let tag_str = tag_obj.downcast::<PyString>()?.to_str()?;
771+
let tag = parse_tag_string(tag_str)?;
772772
let inner = py_to_yaml(py, &value_obj, is_key)?;
773773
return Ok(Yaml::Tagged(Cow::Owned(tag), Box::new(inner)));
774774
}

0 commit comments

Comments
 (0)