Skip to content

Commit

Permalink
rename FromBuffers::bind method to from_buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Jul 15, 2024
1 parent e39d3c6 commit 3cc473f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, 'b> Buffers<'a, 'b> {
pub fn collect<B: FromBuffers<'a, 'b>>(self) -> Option<B> {
let mut iter = self.into_iter();

let result = B::bind(&mut iter)?;
let result = B::from_buffers(&mut iter)?;

if iter.next().is_none() {
Some(result)
Expand Down
50 changes: 25 additions & 25 deletions src/buffers/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::array;
use super::{AnyBuffer, Buffer, BufferMut};

pub trait FromBuffers<'a, 'b>: Sized {
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>;
}

impl<'a, 'b> FromBuffers<'a, 'b> for Buffer<'a, 'b> {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>,
{
Expand All @@ -23,17 +23,17 @@ impl<'a, 'b> FromBuffers<'a, 'b> for Buffer<'a, 'b> {

impl<'a, 'b, const N: usize> FromBuffers<'a, 'b> for [&'b [f32]; N] {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>,
{
Buffer::bind(buffers)?.collect()
Buffer::from_buffers(buffers)?.collect()
}
}

impl<'a, 'b> FromBuffers<'a, 'b> for BufferMut<'a, 'b> {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>,
{
Expand All @@ -46,59 +46,59 @@ impl<'a, 'b> FromBuffers<'a, 'b> for BufferMut<'a, 'b> {

impl<'a, 'b, const N: usize> FromBuffers<'a, 'b> for [&'b mut [f32]; N] {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>,
{
BufferMut::bind(buffers)?.collect()
BufferMut::from_buffers(buffers)?.collect()
}
}

macro_rules! bind_buffers {
($($binding:ident),*) => {
impl<'a, 'b, $($binding),*> FromBuffers<'a, 'b> for ($($binding,)*)
macro_rules! from_buffers {
($($buffer:ident),*) => {
impl<'a, 'b, $($buffer),*> FromBuffers<'a, 'b> for ($($buffer,)*)
where
$($binding: FromBuffers<'a, 'b>),*
$($buffer: FromBuffers<'a, 'b>),*
{
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>,
{
Some((
$(
$binding::bind(buffers)?,
$buffer::from_buffers(buffers)?,
)*
))
}
}
}
}

bind_buffers!(B0);
bind_buffers!(B0, B1);
bind_buffers!(B0, B1, B2);
bind_buffers!(B0, B1, B2, B3);
bind_buffers!(B0, B1, B2, B3, B4);
bind_buffers!(B0, B1, B2, B3, B4, B5);
bind_buffers!(B0, B1, B2, B3, B4, B5, B6);
bind_buffers!(B0, B1, B2, B3, B4, B5, B6, B7);
bind_buffers!(B0, B1, B2, B3, B4, B5, B6, B7, B8);
bind_buffers!(B0, B1, B2, B3, B4, B5, B6, B7, B8, B9);
from_buffers!(B0);
from_buffers!(B0, B1);
from_buffers!(B0, B1, B2);
from_buffers!(B0, B1, B2, B3);
from_buffers!(B0, B1, B2, B3, B4);
from_buffers!(B0, B1, B2, B3, B4, B5);
from_buffers!(B0, B1, B2, B3, B4, B5, B6);
from_buffers!(B0, B1, B2, B3, B4, B5, B6, B7);
from_buffers!(B0, B1, B2, B3, B4, B5, B6, B7, B8);
from_buffers!(B0, B1, B2, B3, B4, B5, B6, B7, B8, B9);

impl<'a, 'b, const N: usize, B> FromBuffers<'a, 'b> for [B; N]
where
B: FromBuffers<'a, 'b>,
{
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
fn from_buffers<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = AnyBuffer<'a, 'b>>,
{
let mut results = array::from_fn(|_| None);

for result in results.iter_mut() {
*result = Some(B::bind(buffers)?);
*result = Some(B::from_buffers(buffers)?);
}

Some(results.map(|result| result.unwrap()))
Expand Down

0 comments on commit 3cc473f

Please sign in to comment.