Skip to content

Commit b995384

Browse files
committed
Improve documentation and expose AtomicSliceRef
1 parent 54dce92 commit b995384

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

texel/src/image/atomic.rs

+38-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
//!
33
//! Re-exported at its super `image` module.
44
use crate::buf::{atomic_buf, AtomicBuffer, AtomicSliceRef};
5-
use crate::image::{raw::RawImage, Coord, IntoPlanesError};
6-
use crate::layout::{
7-
Bytes, Decay, Layout, Mend, PlaneOf, Raster, RasterMut, Relocate, SliceLayout, Take, TryMend,
8-
};
5+
use crate::image::{raw::RawImage, IntoPlanesError};
6+
use crate::layout::{Bytes, Decay, Layout, Mend, PlaneOf, Relocate, SliceLayout, Take, TryMend};
97
use crate::texel::{constants::U8, MAX_ALIGN};
108
use crate::{Texel, TexelBuffer};
119

@@ -84,7 +82,8 @@ impl<L: Layout> AtomicImage<L> {
8482
/// assert_eq!(as_bytes.layout().height(), 400);
8583
/// ```
8684
///
87-
/// See also [`Image::mend`] and [`Image::try_mend`] for operations that reverse the effects.
85+
/// See also [`AtomicImage::mend`] and [`AtomicImage::try_mend`] for operations that reverse
86+
/// the effects.
8887
///
8988
/// Can also be used to forget specifics of the layout, turning the image into a more general
9089
/// container type. For example, to use a uniform type as an allocated buffer waiting on reuse.
@@ -160,21 +159,51 @@ impl<L> AtomicImage<L> {
160159
/// Get a reference to the aligned unstructured bytes of the image.
161160
///
162161
/// Note that this may return more bytes than required for the specific layout for various
163-
/// reasons. See also [`Self::as_capacity_bytes`].
162+
/// reasons. See also [`Self::make_mut`].
164163
pub fn as_capacity_atomic_buf(&self) -> &atomic_buf {
165164
self.inner.as_capacity_atomic_buf()
166165
}
167166

167+
/// Get a mutable reference to all allocated bytes if this image does not alias any other.
168+
///
169+
/// # Example
170+
///
171+
/// ```
172+
/// use image_texel::{image::AtomicImage, layout::Matrix};
173+
///
174+
/// let layout = Matrix::<[u8; 4]>::width_and_height(10, 10).unwrap();
175+
/// let mut image = AtomicImage::new(layout);
176+
/// assert!(image.get_mut().is_some());
177+
///
178+
/// let mut clone_of = image.clone();
179+
/// assert!(image.get_mut().is_none());
180+
/// ```
181+
pub fn get_mut(&mut self) -> Option<&mut atomic_buf> {
182+
self.inner.get_mut().get_mut()
183+
}
184+
168185
/// Ensure this image does not alias any other.
169186
///
187+
/// Then returns a mutable reference to all the bytes allocated in the buffer.
188+
///
189+
/// # Example
190+
///
170191
/// ```
171-
/// use image_texel::{image::AtomicImage, layout::Matrix, layout::Bytes};
192+
/// use image_texel::{image::AtomicImage, layout::Matrix, texels::U8};
193+
/// let texel = U8.array::<4>();
172194
///
173195
/// let layout = Matrix::<[u8; 4]>::width_and_height(10, 10).unwrap();
174196
/// let image = AtomicImage::new(layout);
197+
///
175198
/// let mut clone_of = image.clone();
199+
/// let atomic_mut_buf = clone_of.make_mut();
200+
///
201+
/// // Now these are independent buffers.
202+
/// atomic_mut_buf.as_buf_mut().as_mut_texels(texel)[0] = [0xff; 4];
203+
/// assert_ne!(texel.load_atomic(image.as_slice().index_one(0)), [0xff; 4]);
176204
///
177-
/// let buf = clone_of.make_mut();
205+
/// // With mutable reference we initialized the new buffer.
206+
/// assert_eq!(texel.load_atomic(clone_of.as_slice().index_one(0)), [0xff; 4]);
178207
/// ```
179208
pub fn make_mut(&mut self) -> &mut atomic_buf {
180209
self.inner.get_mut().make_mut()
@@ -308,7 +337,7 @@ impl<'data, L> AtomicImageRef<'data, L> {
308337

309338
/// Decay into a image with less specific layout.
310339
///
311-
/// See [`Image::decay`].
340+
/// See [`AtomicImage::checked_decay`].
312341
pub fn checked_decay<M>(self) -> Option<AtomicImageRef<'data, M>>
313342
where
314343
M: Decay<L>,

texel/src/layout/matrix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait MatrixLayout: Layout {
2222
/// The valid matrix specification of this layout.
2323
///
2424
/// This call should not fail, or panic. Otherwise, prefer an optional getter for the
25-
/// [`StridedBytes`] and have the caller decay their own buffer.
25+
/// [`StridedBytes`][`crate::layout::StridedBytes`] and have the caller decay their own buffer.
2626
fn matrix(&self) -> MatrixBytes;
2727
}
2828

texel/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,8 @@ pub mod texels {
108108
pub use crate::texel::MaxAtomic;
109109
pub use crate::texel::MaxCell;
110110

111-
pub use crate::buf::{atomic_buf, buf, cell_buf, AtomicBuffer, Buffer, CellBuffer, TexelRange};
111+
pub use crate::buf::{
112+
atomic_buf, buf, cell_buf, AtomicBuffer, AtomicRef, AtomicSliceRef, Buffer, CellBuffer,
113+
TexelRange,
114+
};
112115
}

0 commit comments

Comments
 (0)