Skip to content

Commit

Permalink
Allow Buffer types, Reader, and Writer to accept ?Sized types
Browse files Browse the repository at this point in the history
  • Loading branch information
wackbyte authored and teoxoy committed Nov 3, 2023
1 parent 7367909 commit a26b838
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/core/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<B> AsMut<B> for StorageBuffer<B> {
impl<B: BufferMut> StorageBuffer<B> {
pub fn write<T>(&mut self, value: &T) -> Result<()>
where
T: ShaderType + WriteInto,
T: ?Sized + ShaderType + WriteInto,
{
let mut writer = Writer::new(value, &mut self.inner, 0)?;
value.write_into(&mut writer);
Expand All @@ -50,7 +50,7 @@ impl<B: BufferMut> StorageBuffer<B> {
impl<B: BufferRef> StorageBuffer<B> {
pub fn read<T>(&self, value: &mut T) -> Result<()>
where
T: ShaderType + ReadFrom,
T: ?Sized + ShaderType + ReadFrom,
{
let mut writer = Reader::new::<T>(&self.inner, 0)?;
value.read_from(&mut writer);
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<B> AsMut<B> for UniformBuffer<B> {
impl<B: BufferMut> UniformBuffer<B> {
pub fn write<T>(&mut self, value: &T) -> Result<()>
where
T: ShaderType + WriteInto,
T: ?Sized + ShaderType + WriteInto,
{
T::assert_uniform_compat();
self.inner.write(value)
Expand All @@ -114,7 +114,7 @@ impl<B: BufferMut> UniformBuffer<B> {
impl<B: BufferRef> UniformBuffer<B> {
pub fn read<T>(&self, value: &mut T) -> Result<()>
where
T: ShaderType + ReadFrom,
T: ?Sized + ShaderType + ReadFrom,
{
T::assert_uniform_compat();
self.inner.read(value)
Expand Down Expand Up @@ -197,7 +197,7 @@ impl<B> AsMut<B> for DynamicStorageBuffer<B> {
impl<B: BufferMut> DynamicStorageBuffer<B> {
pub fn write<T>(&mut self, value: &T) -> Result<u64>
where
T: ShaderType + WriteInto,
T: ?Sized + ShaderType + WriteInto,
{
let offset = self.offset;

Expand All @@ -213,7 +213,7 @@ impl<B: BufferMut> DynamicStorageBuffer<B> {
impl<B: BufferRef> DynamicStorageBuffer<B> {
pub fn read<T>(&mut self, value: &mut T) -> Result<()>
where
T: ShaderType + ReadFrom,
T: ?Sized + ShaderType + ReadFrom,
{
let mut writer = Reader::new::<T>(&self.inner, self.offset)?;
value.read_from(&mut writer);
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<B> AsMut<B> for DynamicUniformBuffer<B> {
impl<B: BufferMut> DynamicUniformBuffer<B> {
pub fn write<T>(&mut self, value: &T) -> Result<u64>
where
T: ShaderType + WriteInto,
T: ?Sized + ShaderType + WriteInto,
{
T::assert_uniform_compat();
self.inner.write(value)
Expand All @@ -301,7 +301,7 @@ impl<B: BufferMut> DynamicUniformBuffer<B> {
impl<B: BufferRef> DynamicUniformBuffer<B> {
pub fn read<T>(&mut self, value: &mut T) -> Result<()>
where
T: ShaderType + ReadFrom,
T: ?Sized + ShaderType + ReadFrom,
{
T::assert_uniform_compat();
self.inner.read(value)
Expand Down
4 changes: 2 additions & 2 deletions src/core/rw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Writer<B: BufferMut> {

impl<B: BufferMut> Writer<B> {
#[inline]
pub fn new<T: ShaderType>(data: &T, buffer: B, offset: usize) -> Result<Self> {
pub fn new<T: ?Sized + ShaderType>(data: &T, buffer: B, offset: usize) -> Result<Self> {
let mut cursor = Cursor::new(buffer, offset);
let size = data.size().get();
if cursor.try_enlarge(offset + size as usize).is_err() {
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct Reader<B: BufferRef> {

impl<B: BufferRef> Reader<B> {
#[inline]
pub fn new<T: ShaderType + ?Sized>(buffer: B, offset: usize) -> Result<Self> {
pub fn new<T: ?Sized + ShaderType>(buffer: B, offset: usize) -> Result<Self> {
let cursor = Cursor::new(buffer, offset);
if cursor.remaining() < T::min_size().get() as usize {
Err(Error::BufferTooSmall {
Expand Down

0 comments on commit a26b838

Please sign in to comment.