Skip to content

Commit

Permalink
refactor: remove unused trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenautumns committed Jun 20, 2024
1 parent 3d59885 commit 6345e91
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions a653rs-router/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,6 @@ impl<Q: ApexQueuingPortP4> RouterOutput for QueuingPortSender<Q> {
}
}

trait BufferExt {
fn validate_read(&mut self, size: MessageSize) -> Result<&mut Self, PortError>;

/// Validate a buffer to be at most as long as the given usize.
/// If not returns [Self] with the length of the passed buffer
fn validate_write(&self, size: MessageSize) -> Result<&Self, PortError>;
}

impl BufferExt for [ApexByte] {
fn validate_read(&mut self, size: MessageSize) -> Result<&mut Self, PortError> {
if usize::try_from(size)
.map(|ss| self.len() < ss)
.unwrap_or(true)
{
return Err(PortError::Receive);
}
Ok(self)
}

fn validate_write(&self, size: MessageSize) -> Result<&Self, PortError> {
if usize::try_from(size)
.map(|ss| self.len() > ss)
.unwrap_or(false)
|| self.is_empty()
{
return Err(PortError::Send);
}
Ok(self)
}
}

/// An error occured while reading or writing a port of the router.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum PortError {
Expand Down

0 comments on commit 6345e91

Please sign in to comment.