Skip to content

No std bytes writer - #6251

Merged
davidhewitt merged 20 commits into
PyO3:mainfrom
Person-93:no_std_bytes_writer
Aug 24, 2026
Merged

No std bytes writer#6251
davidhewitt merged 20 commits into
PyO3:mainfrom
Person-93:no_std_bytes_writer

Conversation

@Person-93

Copy link
Copy Markdown
Contributor

This is part of the WIP no_std support.

I've made impl of std::io::Write for PyBytesWriter conditional on wip_feature_std. This makes PyBytesWriter completely useless without the std feature, so I've added an additional method write_bytes.

@bschoenmaeckers

Copy link
Copy Markdown
Member

We currently do not expose PyBytesWriter directly. So adding an extra method is not usable right now.

The only usage is a dyn Write ref passed here:

pyo3/src/types/bytes.rs

Lines 160 to 171 in d5daa3d

pub fn new_with_writer<F>(
py: Python<'_>,
reserved_capacity: usize,
write: F,
) -> PyResult<Bound<'_, PyBytes>>
where
F: FnOnce(&mut dyn Write) -> PyResult<()>,
{
let mut writer = PyBytesWriter::with_capacity(py, reserved_capacity)?;
write(&mut writer)?;
writer.try_into()
}

Should we expose PyBytesWriter directly or disable it completely until core has io::Write?

Comment thread src/types/bytes/writer.rs
@Person-93

Copy link
Copy Markdown
Contributor Author

Should we expose PyBytesWriter directly or disable it completely until core has io::Write?

I think it makes sense to expose it directly in that function.

@Person-93
Person-93 force-pushed the no_std_bytes_writer branch 4 times, most recently from f3656a9 to 454af80 Compare August 5, 2026 20:47
@Person-93
Person-93 force-pushed the no_std_bytes_writer branch from 454af80 to 6e24383 Compare August 7, 2026 00:24
Comment thread src/lib.rs Outdated
Comment thread src/types/bytes.rs
@codspeed-hq

codspeed-hq Bot commented Aug 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 141 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing Person-93:no_std_bytes_writer (0d4ba4e) with main (8e0c853)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Person-93
Person-93 force-pushed the no_std_bytes_writer branch 2 times, most recently from d12b735 to 82b8626 Compare August 16, 2026 02:30
@Person-93
Person-93 force-pushed the no_std_bytes_writer branch 4 times, most recently from abb9936 to 82b43c8 Compare August 18, 2026 18:08
@Person-93

Copy link
Copy Markdown
Contributor Author

@davidhewitt , this is rebased after merging #6324

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks generally great, just a couple of small thoughts

Comment thread src/types/bytes/writer.rs Outdated
Comment thread src/types/bytes/writer.rs Outdated

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@davidhewitt
davidhewitt enabled auto-merge August 23, 2026 21:48
auto-merge was automatically disabled August 23, 2026 22:11

Head branch was pushed to by a user without write access

@Person-93
Person-93 force-pushed the no_std_bytes_writer branch from 8286450 to 0d4ba4e Compare August 23, 2026 22:11
@davidhewitt
davidhewitt added this pull request to the merge queue Aug 24, 2026
Merged via the queue into PyO3:main with commit 4b642bc Aug 24, 2026
52 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants