Skip to content

Commit

Permalink
Docs golfing
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrienG2 committed Nov 11, 2019
1 parent 3e3b514 commit 9af4124
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/align/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ impl<'bytes> AlignedReader<'bytes> {
if size > self.bytes.len() { return None; }

// Extract the inner T-typed data
// This is safe because we checked that the input size is large enough
// and the first pointer of a slice cannot be null
let (out, rest) = self.bytes.split_at_mut(size);
let result: NonNull<T> = unsafe { mem::transmute(out.as_mut_ptr()) };
let result: NonNull<T> = unsafe {
NonNull::new_unchecked(out.as_mut_ptr() as *mut T)
};

// Update the inner slice. In an ideal world, one could just write
// self.bytes = rest
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ pub use align::{AlignedReader, AlignedWriter};
/// write down binary data of a type T which contains padding bytes as we must
/// pass down an `&[u8]` to the `Write` API.
///
/// Eliminating this UB will require changes to the Rust languages or `std` so
/// that either 1/there is a non-UB way to turn padding bytes into `&[u8]` or
/// 2/there is a way to send an `&[MaybeUninit<u8>]` (which allows padding
/// bytes) to a Rust writer. See this discussion thread for more info:
/// Eliminating this UB will require changes to the Rust languages or `std` to
/// add either of 1/a non-UB way to turn padding bytes into `&[u8]` or 2/a way
/// to send an `&[MaybeUninit<u8>]` (which allows padding bytes) to a Write
/// implementation. See the following discussion thread for more info:
/// https://internals.rust-lang.org/t/writing-down-binary-data-with-padding-bytes/11197/
///
/// # Examples
Expand Down

0 comments on commit 9af4124

Please sign in to comment.