Diffstat (limited to 'src/build/builders/core/array.rs')
| -rw-r--r-- | src/build/builders/core/array.rs | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/src/build/builders/core/array.rs b/src/build/builders/core/array.rs index 2b8edb3..f3311e5 100644 --- a/src/build/builders/core/array.rs +++ b/src/build/builders/core/array.rs @@ -4,7 +4,7 @@ use crate::{ any_trait, protocol::{ visitor::{Sequence, SequenceScope, Status}, - ControlFlowFor, Effect, Ready, + ControlFlowFor, Effect, }, }; @@ -80,49 +80,56 @@ any_trait! { ]; } -impl<'ctx, B: crate::Builder<'ctx>, const N: usize, E: Effect> Sequence<'ctx, E> +impl<'ctx, B: crate::Builder<'ctx>, const N: usize> Sequence<'ctx> for Builder<'ctx, B, N> { #[inline] - fn visit<'a>(&'a mut self, scope: &'a mut dyn SequenceScope<'ctx, E>) -> ControlFlowFor<'a, E> { - E::wrap(async { - loop { - // Check if the array is full. - if self.index >= N { + fn visit<'a>(&'a mut self, scope: &'a mut dyn SequenceScope<'ctx>) -> ControlFlowFor<'a> { + loop { + // Check if the array is full. + if self.index >= N { + return ControlFlow::Continue(()); + } + + // Try to build the next value. + let mut builder = B::default(); + match scope.next(builder.as_visitor()) { + ControlFlow::Continue(Status::Done) => { + // The sequence is done so the builder wasn't given a value. + // We just throw away the empty builder. return ControlFlow::Continue(()); } - - // Try to build the next value. - let mut builder = B::default(); - match scope.next(builder.as_visitor()).await { - ControlFlow::Continue(Status::Done) => { - // The sequence is done so the builder wasn't given a value. - // We just throw away the empty builder. - return ControlFlow::Continue(()); - } - ControlFlow::Continue(Status::Continue) => match builder.build() { - Ok(value) => { - // Put the value in the array, and move to the next one. - unsafe { maybe_uninit_array(&mut self.array).get_unchecked_mut(self.index).write(value) }; - self.index += 1; - } - Err(err) => { - // Record the item error and return a stop signal. - self.item_err = Some((self.index, err)); - return ControlFlow::Break(()); + ControlFlow::Continue(Status::Continue) => match builder.build() { + Ok(value) => { + // Put the value in the array, and move to the next one. + // unsafe { + // maybe_uninit_array(&mut self.array) + // .get_unchecked_mut(self.index) + // .write(value) + // }; + unsafe { + let ptr = (self.array.as_mut_ptr() as *mut B::Value).offset(self.index as _); + core::ptr::write(ptr, value); } - }, - ControlFlow::Break(()) => { + // std::ptr::write(&mut self.array + self.index += 1; + } + Err(err) => { + // Record the item error and return a stop signal. + self.item_err = Some((self.index, err)); return ControlFlow::Break(()); } + }, + ControlFlow::Break(()) => { + return ControlFlow::Break(()); } } - }) + } } } - -fn maybe_uninit_array<T, const N: usize>( - array: &mut MaybeUninit<[T; N]>, -) -> &mut [MaybeUninit<T>; N] { - unsafe { &mut *(array as *mut _ as *mut [MaybeUninit<T>; N]) } -} +// +// fn maybe_uninit_array<T, const N: usize>( +// array: &mut MaybeUninit<[T; N]>, +// ) -> &mut [MaybeUninit<T>; N] { +// unsafe { &mut *(array as *mut _ as *mut [MaybeUninit<T>; N]) } +// } |