Skip to content

Commit

Permalink
Fix a clippy complaint about complex types
Browse files Browse the repository at this point in the history
error: very complex type used. Consider factoring parts into `type` definitions
   --> src/utils.rs:286:14
    |
286 |         ) -> CallbackFormating<'a, 'b, fn(&mut Formatter<'_>, u32, &[(u32, &str, &str)]) -> Result>
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::type-complexity` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed Nov 21, 2020
1 parent 7e4ea9c commit d3cb811
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,18 @@ mod pretty_printer {
use super::{pretty_print_bitmask, pretty_print_enum};
use std::fmt::{Display, Formatter, Result};

struct CallbackFormating<'a, 'b, F> {
callback: F,
type CallbackType = fn(&mut Formatter<'_>, u32, &[(u32, &str, &str)]) -> Result;

struct CallbackFormating<'a, 'b> {
callback: CallbackType,
value: u32,
cases: &'a [(u32, &'b str, &'b str)],
}

fn new_enum<'a, 'b>(
value: u32,
cases: &'a [(u32, &'b str, &'b str)],
) -> CallbackFormating<'a, 'b, fn(&mut Formatter<'_>, u32, &[(u32, &str, &str)]) -> Result>
) -> CallbackFormating<'a, 'b>
{
CallbackFormating {
callback: pretty_print_enum,
Expand All @@ -295,7 +297,7 @@ mod pretty_printer {
fn new_bitmask<'a, 'b>(
value: u32,
cases: &'a [(u32, &'b str, &'b str)],
) -> CallbackFormating<'a, 'b, fn(&mut Formatter<'_>, u32, &[(u32, &str, &str)]) -> Result>
) -> CallbackFormating<'a, 'b>
{
CallbackFormating {
callback: pretty_print_bitmask,
Expand All @@ -304,10 +306,7 @@ mod pretty_printer {
}
}

impl<F> Display for CallbackFormating<'_, '_, F>
where
F: Fn(&mut Formatter<'_>, u32, &[(u32, &str, &str)]) -> Result,
{
impl Display for CallbackFormating<'_, '_> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
(self.callback)(f, self.value, self.cases)
}
Expand Down

0 comments on commit d3cb811

Please sign in to comment.