@@ -5,7 +5,7 @@ use crate::buf::{atomic_buf, AtomicBuffer, AtomicSliceRef};
55use crate :: image:: { raw:: RawImage , IntoPlanesError } ;
66use crate :: layout:: { Bytes , Decay , Layout , Mend , PlaneOf , Relocate , SliceLayout , Take , TryMend } ;
77use crate :: texel:: { constants:: U8 , MAX_ALIGN } ;
8- use crate :: { Texel , TexelBuffer } ;
8+ use crate :: { BufferReuseError , Texel , TexelBuffer } ;
99
1010/// A container of allocated bytes, parameterized over the layout.
1111///
@@ -77,6 +77,19 @@ impl<L: Layout> AtomicImage<L> {
7777 . map_err ( Into :: into)
7878 }
7979
80+ /// Attempt to modify the layout to a new value, without modifying its type.
81+ ///
82+ /// Returns an `Err` if the layout does not fit the underlying buffer. Otherwise returns `Ok`
83+ /// and overwrites the layout accordingly.
84+ ///
85+ /// TODO: public name and provide a `set_capacity` for `L = Bytes`?
86+ pub ( crate ) fn try_set_layout ( & mut self , layout : L ) -> Result < ( ) , BufferReuseError >
87+ where
88+ L : Layout ,
89+ {
90+ self . inner . try_reuse ( layout)
91+ }
92+
8093 /// Decay into a image with less specific layout.
8194 ///
8295 /// See the [`Decay`] trait for an explanation of this operation.
@@ -387,6 +400,19 @@ impl<'data, L> AtomicImageRef<'data, L> {
387400 Some ( self . inner . try_reinterpret ( layout) . ok ( ) ?. into ( ) )
388401 }
389402
403+ /// Attempt to modify the layout to a new value, without modifying its type.
404+ ///
405+ /// Returns an `Err` if the layout does not fit the underlying buffer. Otherwise returns `Ok`
406+ /// and overwrites the layout accordingly.
407+ ///
408+ /// TODO: public name and provide a `set_capacity` for `L = Bytes`?
409+ pub ( crate ) fn try_set_layout ( & mut self , layout : L ) -> Result < ( ) , BufferReuseError >
410+ where
411+ L : Layout ,
412+ {
413+ self . inner . try_reuse ( layout)
414+ }
415+
390416 /// Decay into a image with less specific layout.
391417 ///
392418 /// See [`AtomicImage::decay`].
0 commit comments