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

feat: add copy_*e_to_slice family #423

Closed
wants to merge 13 commits into from
Closed

Conversation

prestwich
Copy link
Collaborator

Motivation

Add convenient methods for writing Uints to pre-allocated buffers

Solution

fn copy_le_to_slice()
fn checked_copy_le_to_slice()
fn copy_be_to_slice()
fn checked_copy_be_to_slice()

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@prestwich prestwich added the enhancement New feature or request label Dec 24, 2024
@prestwich prestwich self-assigned this Dec 24, 2024
src/bytes.rs Outdated Show resolved Hide resolved
src/bytes.rs Outdated Show resolved Hide resolved
@prestwich prestwich force-pushed the prestwich/copy-to-buf branch from ab04803 to 60147b0 Compare December 25, 2024 15:11
@prestwich prestwich force-pushed the prestwich/copy-to-buf branch from 55c7ef2 to 4bd34e1 Compare December 26, 2024 15:42
Copy link
Contributor

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

LGTM. We should start running tests in a big-endian environment in CI

let bytes = self.as_le_bytes();
writer.write_all(&bytes[..Self::BYTES])
#[cfg(target_endian = "little")]
return writer.write_all(&self.as_le_slice()[..Self::BYTES]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return writer.write_all(&self.as_le_slice()[..Self::BYTES]);
return writer.write_all(self.as_le_slice());

@prestwich prestwich force-pushed the prestwich/copy-to-buf branch from b6c3d74 to 45d2694 Compare December 27, 2024 14:31
Copy link
Contributor

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

LGTM

#[cfg(target_endian = "little")]
return writer.write_all(self.as_le_slice());

// TODO: Replace the unsafety with `generic_const_exprs` when
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have an issue for this filed?

Copy link
Collaborator Author

@prestwich prestwich Dec 30, 2024

Choose a reason for hiding this comment

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

The actions bot will auto file it when the PR is merged

@Evalir Evalir mentioned this pull request Dec 30, 2024
3 tasks
@prestwich
Copy link
Collaborator Author

prestwich commented Dec 30, 2024

closing in favor of #424

@prestwich prestwich closed this Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants