Skip to content

Commit

Permalink
use derive_more::Into for all these
Browse files Browse the repository at this point in the history
  • Loading branch information
haileys committed Feb 14, 2024
1 parent fb6191f commit 80c7dce
Showing 1 changed file with 6 additions and 44 deletions.
50 changes: 6 additions & 44 deletions bark-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![no_std]

use derive_more::Into;

pub mod buffer;
pub mod packet;
pub mod time;
Expand All @@ -10,56 +12,16 @@ pub const CHANNELS: ChannelCount = ChannelCount(2);
pub const FRAMES_PER_PACKET: usize = 120; // 2.5ms at 48khz, compatible with opus
pub const SAMPLES_PER_PACKET: usize = CHANNELS.0 as usize * FRAMES_PER_PACKET;

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Into)]
#[into(types(u64, u128, i64, f64))]
pub struct SampleRate(pub u32);

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Into)]
#[into(types(usize, u32, u64))]
pub struct ChannelCount(pub u16);

impl From<SampleRate> for usize {
fn from(value: SampleRate) -> Self {
value.0.try_into().expect("SampleRate -> usize")
}
}

impl From<SampleRate> for u32 {
fn from(value: SampleRate) -> Self {
value.0.into()
}
}

impl From<SampleRate> for u64 {
fn from(value: SampleRate) -> Self {
value.0.into()
}
}

impl From<SampleRate> for u128 {
fn from(value: SampleRate) -> Self {
value.0.into()
}
}

impl From<SampleRate> for i64 {
fn from(value: SampleRate) -> Self {
value.0.into()
}
}

impl From<ChannelCount> for usize {
fn from(value: ChannelCount) -> Self {
value.0.into()
}
}

impl From<ChannelCount> for u64 {
fn from(value: ChannelCount) -> Self {
value.0.into()
}
}

impl From<ChannelCount> for u32 {
fn from(value: ChannelCount) -> Self {
value.0.into()
}
}

0 comments on commit 80c7dce

Please sign in to comment.