From 495ecba713c0cf0cc9d81f334a785a3e849d6ac3 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 19 Sep 2023 10:41:02 -0400 Subject: [PATCH] rust: various cleanups and move to Rust 2021 --- Cargo.toml | 2 +- src/console.rs | 25 ++++++++++++++----------- src/file.rs | 21 ++++++++++++--------- src/win.rs | 12 ++++++------ 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1fb776..08527aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ readme = "README.md" keywords = ["windows", "winapi", "util", "win"] license = "Unlicense/MIT" categories = ["os::windows-apis", "external-ffi-bindings"] -edition = "2018" +edition = "2021" [target.'cfg(windows)'.dependencies.winapi] version = "0.3" diff --git a/src/console.rs b/src/console.rs index 233d5c9..44af5bd 100644 --- a/src/console.rs +++ b/src/console.rs @@ -1,13 +1,16 @@ -use std::io; -use std::mem; - -use winapi::shared::minwindef::WORD; -use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode}; -use winapi::um::wincon::{ - self, GetConsoleScreenBufferInfo, SetConsoleTextAttribute, - CONSOLE_SCREEN_BUFFER_INFO, FOREGROUND_BLUE as FG_BLUE, - FOREGROUND_GREEN as FG_GREEN, FOREGROUND_INTENSITY as FG_INTENSITY, - FOREGROUND_RED as FG_RED, +use std::{io, mem}; + +use winapi::{ + shared::minwindef::WORD, + um::{ + consoleapi::{GetConsoleMode, SetConsoleMode}, + wincon::{ + self, GetConsoleScreenBufferInfo, SetConsoleTextAttribute, + CONSOLE_SCREEN_BUFFER_INFO, FOREGROUND_BLUE as FG_BLUE, + FOREGROUND_GREEN as FG_GREEN, + FOREGROUND_INTENSITY as FG_INTENSITY, FOREGROUND_RED as FG_RED, + }, + }, }; use crate::{AsHandleRef, HandleRef}; @@ -208,7 +211,7 @@ impl Console { let h = kind.handle(); let info = screen_buffer_info(&h)?; let attr = TextAttributes::from_word(info.attributes()); - Ok(Console { kind: kind, start_attr: attr, cur_attr: attr }) + Ok(Console { kind, start_attr: attr, cur_attr: attr }) } /// Create a new Console to stdout. diff --git a/src/file.rs b/src/file.rs index 56a1e41..cdbcca3 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,13 +1,16 @@ -use std::io; -use std::mem; - -use winapi::shared::minwindef::FILETIME; -use winapi::shared::winerror::NO_ERROR; -use winapi::um::errhandlingapi::GetLastError; -use winapi::um::fileapi::{ - GetFileInformationByHandle, GetFileType, BY_HANDLE_FILE_INFORMATION, +use std::{io, mem}; + +use winapi::{ + shared::{minwindef::FILETIME, winerror::NO_ERROR}, + um::{ + errhandlingapi::GetLastError, + fileapi::{ + GetFileInformationByHandle, GetFileType, + BY_HANDLE_FILE_INFORMATION, + }, + winnt, + }, }; -use winapi::um::winnt; use crate::AsHandleRef; diff --git a/src/win.rs b/src/win.rs index 9c77c0d..f64585e 100644 --- a/src/win.rs +++ b/src/win.rs @@ -1,10 +1,10 @@ -use std::fs::File; -use std::io; -use std::os::windows::io::{ - AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle, +use std::{ + fs::File, + io, + os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle}, + path::Path, + process, }; -use std::path::Path; -use std::process; /// A handle represents an owned and valid Windows handle to a file-like /// object.