Skip to content

Commit

Permalink
Enforce usage of const fn more aggresively
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Aug 29, 2023
1 parent ceb8623 commit 9ae3a65
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/devices/korg_kaoss_dj/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
const LED_OFF: u8 = 0x00;
const LED_ON: u8 = 0x7f;

fn led_to_u7(output: LedOutput) -> u8 {
const fn led_to_u7(output: LedOutput) -> u8 {
match output {
LedOutput::Off => LED_OFF,
LedOutput::On => LED_ON,
Expand Down Expand Up @@ -148,7 +148,7 @@ impl TryFrom<ControlIndex> for Led {
}

#[must_use]
pub fn led_output_into_midi_message(led: Led, output: LedOutput) -> [u8; 3] {
pub const fn led_output_into_midi_message(led: Led, output: LedOutput) -> [u8; 3] {
let (status, data1) = match led {
Led::Main(led) => match led {
MainLed::TabButton => (MIDI_STATUS_BUTTON_MAIN, MIDI_TAP_BUTTON),
Expand Down
2 changes: 1 addition & 1 deletion src/devices/ni_traktor_kontrol_s4mk3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl DeviceContext {
}

#[must_use]
pub fn info(&self) -> &DeviceInfo {
pub const fn info(&self) -> &DeviceInfo {
&self.info
}

Expand Down
2 changes: 1 addition & 1 deletion src/devices/pioneer_ddj_400/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl PerformancePadSensor {
Self::KeyShift(nr) => nr + 0x70,
}
}
fn try_from_u8(pad_id: u8) -> Option<Self> {
const fn try_from_u8(pad_id: u8) -> Option<Self> {
let sensor = match pad_id {
0x00..=0x07 => Self::HotCue(pad_id),
0x10..=0x17 => Self::PadFx1(pad_id - 0x10),
Expand Down
6 changes: 3 additions & 3 deletions src/hid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,20 @@ impl<'a> TryFrom<&'a DeviceInfo> for DeviceId<'a> {

impl HidDevice {
#[must_use]
pub fn new(info: DeviceInfo) -> Self {
pub const fn new(info: DeviceInfo) -> Self {
Self {
info,
connected: None,
}
}

#[must_use]
pub fn info(&self) -> &DeviceInfo {
pub const fn info(&self) -> &DeviceInfo {
&self.info
}

#[must_use]
pub fn is_connected(&self) -> bool {
pub const fn is_connected(&self) -> bool {
self.connected.is_some()
}

Expand Down
2 changes: 1 addition & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub trait ControlInputEventSink {

#[must_use]
pub fn split_crossfader_input_linear(input: CenterSliderInput) -> (SliderInput, SliderInput) {
fn f_x(x: f32) -> f32 {
const fn f_x(x: f32) -> f32 {
x
}
let CenterSliderInput { position } = input;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![warn(clippy::pedantic)]
// Additional restrictions
#![warn(clippy::clone_on_ref_ptr)]
#![warn(clippy::missing_const_for_fn)]
#![warn(clippy::self_named_module_files)]
// Repetitions of module/type names occur frequently when using many
// modules for keeping the size of the source files handy. Often
Expand Down
10 changes: 5 additions & 5 deletions src/midi/midir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where
I: MidiInputGateway + Send,
{
#[must_use]
fn new(
const fn new(
descriptor: MidiDeviceDescriptor,
input_port: MidirInputPort,
output_port: MidirOutputPort,
Expand All @@ -87,17 +87,17 @@ where
}

#[must_use]
pub fn descriptor(&self) -> &MidiDeviceDescriptor {
pub const fn descriptor(&self) -> &MidiDeviceDescriptor {
&self.descriptor
}

#[must_use]
pub fn input_port(&self) -> &MidirInputPort {
pub const fn input_port(&self) -> &MidirInputPort {
&self.input_port
}

#[must_use]
pub fn output_port(&self) -> &MidirOutputPort {
pub const fn output_port(&self) -> &MidirOutputPort {
&self.output_port
}

Expand All @@ -119,7 +119,7 @@ where
}

#[must_use]
pub fn is_connected(&self) -> bool {
pub const fn is_connected(&self) -> bool {
self.input_connection.is_some()
}

Expand Down
2 changes: 1 addition & 1 deletion src/param/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl AtomicValue {
}

#[must_use]
pub fn value_type(&self) -> ValueType {
pub const fn value_type(&self) -> ValueType {
match self {
Self::Bool(_) => ValueType::Bool,
Self::I32(_) => ValueType::I32,
Expand Down
4 changes: 2 additions & 2 deletions src/param/ramping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn steps_as_f32(steps: usize) -> f32 {
impl RampingF32 {
/// Create an immediate value without interpolation
#[must_use]
pub fn new(value: f32) -> Self {
pub const fn new(value: f32) -> Self {
Self {
profile: RampingProfile::immediate(),
initial_value: value,
Expand Down Expand Up @@ -106,7 +106,7 @@ impl RampingF32 {
}

#[must_use]
pub fn target_value(&self) -> f32 {
pub const fn target_value(&self) -> f32 {
self.target_value
}

Expand Down

0 comments on commit 9ae3a65

Please sign in to comment.