Skip to content

Commit

Permalink
improve ergonomics
Browse files Browse the repository at this point in the history
* slices from plane refs can last as long as the borrow from the plane,
  not the slice itself. This makes signatures similar to
  `fn plane<F: Frame>(frame: F) -> &[u8]` possible.

* allow `ConsecutiveFrame`s to be cloned if the underlying storage
  is cloneable, e.g. if it's just a slice.
  • Loading branch information
scottlamb committed Jun 18, 2024
1 parent 4e0f5f8 commit 7749e4f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct FramePlaneRef<'a> {
_phantom: PhantomData<&'a [u8]>,
}

impl FramePlaneRef<'_> {
impl<'p> FramePlaneRef<'p> {
/// Creates a new `FramePlaneRef`.
///
/// # Safety
Expand Down Expand Up @@ -120,7 +120,7 @@ impl FramePlaneRef<'_> {
///
/// Panics if the frame has not been initialized.
#[inline]
pub fn as_slice(&self) -> &[u8] {
pub fn as_slice(&self) -> &'p [u8] {
assert!(self.initialized);
unsafe { std::slice::from_raw_parts(self.data, self.len) }
}
Expand Down Expand Up @@ -328,6 +328,7 @@ impl_slice_storage!(u8 { preinitialized=true });
impl_slice_storage!(MaybeUninit<u8> { preinitialized=false });

/// A frame which stores all planes consecutively.
#[derive(Clone)]
pub struct ConsecutiveFrame<S> {
initialized: bool,
format: PixelFormat,
Expand Down

0 comments on commit 7749e4f

Please sign in to comment.