Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accessor methods to PyByteArray #967

Merged
merged 1 commit into from
Jun 13, 2020

Conversation

davidhewitt
Copy link
Member

@davidhewitt davidhewitt commented Jun 8, 2020

Closes #632 .

This adds PyByteArray::data and PyByteArray::as_bytes as proposed in that issue.

I decided to also add as_bytes_mut, but if you think it's too far I can happily remove it. (Users can always implement themselves using std::slice::from_raw_parts_mut(b.data(), b.len()).)

@davidhewitt davidhewitt force-pushed the bytearray-as-bytes branch 2 times, most recently from 043e35c to b313d16 Compare June 8, 2020 21:13
/// Get the contents of this buffer as a slice.
///
/// # Safety
/// This is equivalent to `std::slice::from_raw_parts(self.data(), self.len())`, and so all
Copy link
Member

Choose a reason for hiding this comment

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

This document is well written, but could you please emphasize that we should not resize or delete the bytearray while holding the slice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, tweaked the doc slightly - what do you think of it now?

Copy link
Member

Choose a reason for hiding this comment

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

👍

@kngwyu
Copy link
Member

kngwyu commented Jun 13, 2020

Thank you!

@kngwyu kngwyu merged commit bbdca6b into PyO3:master Jun 13, 2020
@davidhewitt davidhewitt deleted the bytearray-as-bytes branch December 24, 2021 02:04
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.

Add fn as_bytes to PyByteArray
2 participants