move WriteOnly to wgpu-types (#9236)

* move WriteOnly to wgpu-types

* un-pub mod, because pub use * is already in play

* fixup doctests

* link to wgpu items
This commit is contained in:
Chris Biscardi authored and GitHub committed 2026-03-16 08:37:17 -04:00
1 parent 96b7872f77
commit 252ef09792
3 files changed
+19 -8

No files matched your search

+2
View File
@@ -49,6 +49,7 @@ mod texture;
mod tokens;
mod transfers;
mod vertex;
mod write_only;
pub use adapter::*;
pub use backend::*;
@@ -70,6 +71,7 @@ pub use texture::*;
pub use tokens::*;
pub use transfers::*;
pub use vertex::*;
pub use write_only::*;
/// Create a Markdown link definition referring to the `wgpu` crate.
///
@@ -20,10 +20,12 @@ use core::{
ptr::NonNull,
};
use crate::link_to_wgpu_item;
/// Like `&'a mut T`, but allows only write operations.
///
/// This pointer type is obtained from [`BufferViewMut`][crate::BufferViewMut] and
/// [`QueueWriteBufferView`][crate::QueueWriteBufferView].
/// This pointer type is obtained from [`BufferViewMut`] and
/// [`QueueWriteBufferView`].
/// It is an unfortunate necessity due to the fact that mapped GPU memory may be [write combining],
/// which means it cannot work normally with all of the things that Rust `&mut` access allows you to
/// do.
@@ -38,6 +40,8 @@ use core::{
// FIXME: Add an introduction to the necessity of explicit reborrowing.
///
/// [write combining]: https://en.wikipedia.org/wiki/Write_combining
#[doc = link_to_wgpu_item!(struct BufferViewMut)]
#[doc = link_to_wgpu_item!(struct QueueWriteBufferView)]
pub struct WriteOnly<'a, T: ?Sized> {
/// The data which this write-only reference allows **writing** to.
///
@@ -107,6 +111,7 @@ impl<'a, T: ?Sized> WriteOnly<'a, T> {
/// # Example
///
/// ```
/// # use wgpu_types as wgpu;
/// fn write_numbers(slice: wgpu::WriteOnly<[u32]>) {
/// for (i, mut elem) in slice.into_iter().enumerate() {
/// elem.write(i as u32);
@@ -177,6 +182,7 @@ impl<'a, T> WriteOnly<'a, [T]> {
/// # Example
///
/// ```
/// # use wgpu_types as wgpu;
/// let example_slice: &mut [u8] = &mut [0; 10];
/// assert_eq!(wgpu::WriteOnly::from_mut(example_slice).len(), example_slice.len());
/// ```
@@ -203,6 +209,7 @@ impl<'a, T> WriteOnly<'a, [T]> {
/// # Example
///
/// ```
/// # use wgpu_types as wgpu;
/// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead.
/// let mut data: [u8; 9] = [0; 9];
/// let mut wo = wgpu::WriteOnly::from_mut(data.as_mut_slice());
@@ -259,6 +266,7 @@ impl<'a, T> WriteOnly<'a, [T]> {
/// # Example
///
/// ```
/// # use wgpu_types as wgpu;
/// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead.
/// let mut buf: [u8; 10] = [0; 10];
/// let wo = wgpu::WriteOnly::from_mut(buf.as_mut_slice());
@@ -305,6 +313,7 @@ impl<'a, T> WriteOnly<'a, [T]> {
/// # Example
///
/// ```
/// # use wgpu_types as wgpu;
/// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead.
/// let mut buf = vec![0; 10];
/// let mut wo = wgpu::WriteOnly::from_mut(buf.as_mut_slice());
@@ -357,6 +366,7 @@ impl<'a, T> WriteOnly<'a, [T]> {
/// # Example
///
/// ```
/// # use wgpu_types as wgpu;
/// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead.
/// let mut buf = vec![0; 5];
/// let mut wo = wgpu::WriteOnly::from_mut(buf.as_mut_slice());
@@ -415,6 +425,7 @@ impl<'a, T> WriteOnly<'a, [T]> {
/// (If a transformation is not required, use [`WriteOnly::copy_from_slice()`].)
///
/// ```
/// # use wgpu_types as wgpu;
/// fn write_text_as_chars(text: &str, output: wgpu::WriteOnly<[u8]>) {
/// let (mut output, _remainder) = output.into_chunks::<{ size_of::<u32>() }>();
/// output.write_iter(text.chars().map(|ch| (ch as u32).to_ne_bytes()));
+4 -6
View File
@@ -116,7 +116,6 @@ mod cmp;
mod dispatch;
mod macros;
pub mod util;
mod write_only;
//
//
@@ -151,12 +150,11 @@ pub use wgt::{
SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension,
TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType,
TextureTransition, TextureUsages, TextureUses, TextureViewDimension, Trace, VertexAttribute,
VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT,
COPY_BYTES_PER_ROW_ALIGNMENT, IMMEDIATE_DATA_ALIGNMENT, MAP_ALIGNMENT,
MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE, QUERY_RESOLVE_BUFFER_ALIGNMENT,
QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT,
VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, WriteOnly,
WriteOnlyIter, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, IMMEDIATE_DATA_ALIGNMENT,
MAP_ALIGNMENT, MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE,
QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT,
};
pub use write_only::{WriteOnly, WriteOnlyIter};
#[expect(deprecated)]
pub use wgt::VERTEX_STRIDE_ALIGNMENT;