Skip to content

Commit

Permalink
Fix Sized issue in InputEvents trait
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl committed Nov 19, 2023
1 parent af76b81 commit 51127df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
21 changes: 4 additions & 17 deletions common/src/events/io/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::utils::handle_panic;
use clap_sys::events::{clap_event_header, clap_input_events, clap_output_events};

#[allow(clippy::len_without_is_empty)] // This is not necessary, the trait is intended for FFI
pub trait InputEventBuffer {
pub trait InputEventBuffer: Sized {
fn len(&self) -> u32;
fn get(&self, index: u32) -> Option<&UnknownEvent>;
}

pub trait OutputEventBuffer {
pub trait OutputEventBuffer: Sized {
fn try_push(&mut self, event: &UnknownEvent<'static>) -> Result<(), TryPushError>;
}

Expand Down Expand Up @@ -117,19 +117,6 @@ impl<T: Event<'static>, const N: usize> InputEventBuffer for [T; N] {
}
}

impl<T: Event<'static>> InputEventBuffer for [T] {
#[inline]
fn len(&self) -> u32 {
let len = <[T]>::len(self);
len.min((u32::MAX - 1) as usize) as u32
}

#[inline]
fn get(&self, index: u32) -> Option<&UnknownEvent> {
<[T]>::get(self, index as usize).map(|e| e.as_unknown())
}
}

impl<'a, T: Event<'a>> InputEventBuffer for &'a [T] {
#[inline]
fn len(&self) -> u32 {
Expand All @@ -143,7 +130,7 @@ impl<'a, T: Event<'a>> InputEventBuffer for &'a [T] {
}
}

impl<'a> InputEventBuffer for UnknownEvent<'a> {
impl<'a> InputEventBuffer for &UnknownEvent<'a> {
#[inline]
fn len(&self) -> u32 {
1
Expand All @@ -170,7 +157,7 @@ impl<'a, const N: usize> InputEventBuffer for [&UnknownEvent<'a>; N] {
}
}

impl<'a> InputEventBuffer for [&UnknownEvent<'a>] {
impl<'a> InputEventBuffer for &[&UnknownEvent<'a>] {
#[inline]
fn len(&self) -> u32 {
let len = <[&UnknownEvent<'a>]>::len(self);
Expand Down
2 changes: 1 addition & 1 deletion common/src/events/io/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct InputEvents<'a> {
}

impl<'a> InputEvents<'a> {
/// Creates a shared reference to an InputEvents list from a given C FFI-compatible pointer.
/// Creates a shared reference to an [`InputEvents`] list from a given C FFI-compatible pointer.
///
/// # Safety
/// The caller must ensure the given pointer is valid for the lifetime `'a`.
Expand Down

0 comments on commit 51127df

Please sign in to comment.