Skip to content

Commit

Permalink
[rs] Merge gfx-rs#574
Browse files Browse the repository at this point in the history
574: Implement AsRef for BufferView r=kvark a=de-vri-es

This PR implements `AsRef` and `AsMut` in addition to `Deref` and `DerefMut` for `BufferView` and `BufferViewMut`.

This allows the buffer views to be used directly by generic code that wants an `AsRef<[u8]>`.

It's also subjectively a small win when you want to pass the views to non-generic code. I find `buffer.as_ref()` clearer than `&*buffer`. That also goes for `buffer.deref()`, but `Deref` is not in the prelude.

Co-authored-by: Maarten de Vries <[email protected]>
  • Loading branch information
bors[bot] and de-vri-es authored Sep 21, 2020
2 parents 4b1c363 + 81df9fb commit 9a40261
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,18 @@ impl std::ops::DerefMut for BufferViewMut<'_> {
}
}

impl AsRef<[u8]> for BufferView<'_> {
fn as_ref(&self) -> &[u8] {
self.data
}
}

impl AsMut<[u8]> for BufferViewMut<'_> {
fn as_mut(&mut self) -> &mut [u8] {
self.data
}
}

impl Drop for BufferView<'_> {
fn drop(&mut self) {
self.slice
Expand Down

0 comments on commit 9a40261

Please sign in to comment.