Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Biggio committed Apr 5, 2024
1 parent 8791245 commit 8b89a74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 7 additions & 5 deletions cplex-rs/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::ffi::{c_void, CString};

use crate::{
errors::{self, Result},
logging::{get_trampoline, LoggingCallback, StreamType, DEFAULT_LOGGING_CLOSURE},
logging::{
get_trampoline, LoggingCallback, LoggingClosure, StreamType, DEFAULT_LOGGING_CLOSURE,
},
parameters::{Parameter, ParameterValue},
};
use ffi::{
Expand Down Expand Up @@ -30,7 +32,7 @@ mod macros {

pub struct Environment {
pub(crate) inner: *mut cpxenv,
pub(crate) logging_closures: [Option<(Box<dyn Fn(&str)>, LoggingCallback)>; 4],
pub(crate) logging_closures: [Option<(LoggingClosure, LoggingCallback)>; 4],
}

impl Environment {
Expand Down Expand Up @@ -75,7 +77,7 @@ impl Environment {
assert!(!channel.is_null());

if let Some((mut previous_closure, previous_trampoline)) =
self.logging_closures[stream_type.to_index()].take()
self.logging_closures[stream_type.as_index()].take()
{
macros::cpx_env_result!(unsafe {
CPXdelfuncdest(
Expand All @@ -100,7 +102,7 @@ impl Environment {
assert!(!channel.is_null());

if let Some((mut previous_closure, previous_trampoline)) =
self.logging_closures[stream_type.to_index()].take()
self.logging_closures[stream_type.as_index()].take()
{
macros::cpx_env_result!(unsafe {
CPXdelfuncdest(
Expand All @@ -123,7 +125,7 @@ impl Environment {
)
})?;

self.logging_closures[stream_type.to_index()] = Some((new_closure, new_trampoline));
self.logging_closures[stream_type.as_index()] = Some((new_closure, new_trampoline));

Ok(())
}
Expand Down
8 changes: 3 additions & 5 deletions cplex-rs/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::ffi::{c_char, c_void, CStr};

pub type LoggingCallback = Option<unsafe extern "C" fn(*mut c_void, *const c_char)>;
pub type LoggingClosure = Box<dyn Fn(&str)>;

pub(crate) const RESULTS_STREAM_IDX: usize = 0;
pub(crate) const WARNING_STREAM_IDX: usize = 1;
pub(crate) const ERROR_STREAM_IDX: usize = 2;
pub(crate) const LOG_STREAM_IDX: usize = 3;

pub(crate) const DEFAULT_LOGGING_CLOSURE: Option<(
Box<(dyn for<'a> Fn(&'a str) + 'static)>,
LoggingCallback,
)> = None;
pub(crate) const DEFAULT_LOGGING_CLOSURE: Option<(LoggingClosure, LoggingCallback)> = None;

#[derive(Clone, Copy, Debug)]
pub enum StreamType {
Expand All @@ -21,7 +19,7 @@ pub enum StreamType {
}

impl StreamType {
pub(crate) fn to_index(&self) -> usize {
pub(crate) fn as_index(&self) -> usize {
match self {
Self::Results => RESULTS_STREAM_IDX,
Self::Warning => WARNING_STREAM_IDX,
Expand Down

0 comments on commit 8b89a74

Please sign in to comment.