Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Zhiburt <[email protected]>
  • Loading branch information
zhiburt committed Jul 24, 2023
1 parent cf36a1e commit 03ae7b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
20 changes: 10 additions & 10 deletions papergrid/examples/color_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use std::{
collections::HashMap,
fmt::{Display, Formatter},
io::Write,
fmt::{self, Display, Formatter},
io::{self, Write},
};

use owo_colors::{
Expand Down Expand Up @@ -39,7 +39,7 @@ fn main() {

let grid = Grid::new(records, &dimension, &cfg, &colors);

grid.build(UTF8Stdout(std::io::stdout())).unwrap();
grid.build(UTF8Stdout(io::stdout())).unwrap();
println!();
}

Expand Down Expand Up @@ -70,7 +70,7 @@ fn generate_table_config() -> SpannedConfig {
struct Style(OStyle);

impl Color for Style {
fn fmt_prefix<W: std::fmt::Write>(&self, f: &mut W) -> std::fmt::Result {
fn fmt_prefix<W: fmt::Write>(&self, f: &mut W) -> fmt::Result {
let buf = OStylePrefix(&self.0).to_string();
f.write_str(&buf)
}
Expand All @@ -79,26 +79,26 @@ impl Color for Style {
struct OStylePrefix<'a>(&'a OStyle);

impl Display for OStylePrefix<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.0.fmt_prefix(f)
}
}

struct UTF8Stdout(std::io::Stdout);
struct UTF8Stdout(io::Stdout);

impl std::fmt::Write for UTF8Stdout {
fn write_str(&mut self, s: &str) -> std::fmt::Result {
impl fmt::Write for UTF8Stdout {
fn write_str(&mut self, s: &str) -> fmt::Result {
let mut buf = s.as_bytes();
loop {
let n = self.0.write(buf).map_err(|_| std::fmt::Error::default())?;
let n = self.0.write(buf).map_err(|_| fmt::Error)?;
if n == buf.len() {
break;
}

buf = &buf[n..];
}

self.0.flush().map_err(|_| std::fmt::Error::default())?;
self.0.flush().map_err(|_| fmt::Error)?;

Ok(())
}
Expand Down
17 changes: 10 additions & 7 deletions papergrid/examples/papergrid_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//! grid cells. `Grid::new(_, _, _, NoColors)` indicates that a color
//! map is not provided. NOT that colors are ignored in the output.

use std::io::Write;
use std::{
fmt,
io::{self, Write},
};

use papergrid::{
colors::NoColors, config::spanned::SpannedConfig, config::Borders,
Expand All @@ -28,7 +31,7 @@ fn main() {

let grid = Grid::new(&records, &dimension, &cfg, NoColors);

grid.build(UTF8Stdout(std::io::stdout())).unwrap();
grid.build(UTF8Stdout(io::stdout())).unwrap();
println!();
}

Expand All @@ -48,21 +51,21 @@ fn generate_table_config() -> SpannedConfig {
cfg
}

struct UTF8Stdout(std::io::Stdout);
struct UTF8Stdout(io::Stdout);

impl std::fmt::Write for UTF8Stdout {
fn write_str(&mut self, s: &str) -> std::fmt::Result {
impl fmt::Write for UTF8Stdout {
fn write_str(&mut self, s: &str) -> fmt::Result {
let mut buf = s.as_bytes();
loop {
let n = self.0.write(buf).map_err(|_| std::fmt::Error::default())?;
let n = self.0.write(buf).map_err(|_| fmt::Error)?;
if n == buf.len() {
break;
}

buf = &buf[n..];
}

self.0.flush().map_err(|_| std::fmt::Error::default())?;
self.0.flush().map_err(|_| fmt::Error)?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tabled/src/tables/util/utf8_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ impl<W> fmt::Write for UTF8Writer<W>
where
W: io::Write,
{
fn write_str(&mut self, s: &str) -> std::fmt::Result {
fn write_str(&mut self, s: &str) -> fmt::Result {
let mut buf = s.as_bytes();
loop {
let n = self.0.write(buf).map_err(|_| std::fmt::Error::default())?;
let n = self.0.write(buf).map_err(|_| fmt::Error)?;
if n == buf.len() {
break;
}
Expand Down

0 comments on commit 03ae7b4

Please sign in to comment.