Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix future object safety of BufferAccess #966

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions vulkano/src/buffer/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ pub unsafe trait BufferAccess: DeviceOwned {
/// Returns the size of the buffer in bytes.
fn size(&self) -> usize;

/// Returns the length of the buffer in number of elements.
///
/// This method can only be called for buffers whose type is known to be an array.
#[inline]
fn len(&self) -> usize
where Self: TypedBufferAccess,
Self::Content: Content
{
self.size() / <Self::Content as Content>::indiv_size()
}

/// Builds a `BufferSlice` object holding the buffer by reference.
#[inline]
fn as_buffer_slice(&self) -> BufferSlice<Self::Content, &Self>
Expand Down Expand Up @@ -208,6 +197,14 @@ unsafe impl<T> BufferAccess for T
pub unsafe trait TypedBufferAccess: BufferAccess {
/// The type of the content.
type Content: ?Sized;

/// Returns the length of the buffer in number of elements.
///
/// This method can only be called for buffers whose type is known to be an array.
#[inline]
fn len(&self) -> usize where Self::Content: Content {
self.size() / <Self::Content as Content>::indiv_size()
}
}

unsafe impl<T> TypedBufferAccess for T
Expand Down