From: Ben Pfaff Date: Wed, 24 Sep 2025 00:16:56 +0000 (-0700) Subject: rust: Run `cargo fmt`. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe27af6fc2408e24d2a1c7571f51254a62575f83;p=pspp rust: Run `cargo fmt`. --- diff --git a/rust/pspp/build.rs b/rust/pspp/build.rs index 13e9534d16..ff821f6f91 100644 --- a/rust/pspp/build.rs +++ b/rust/pspp/build.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License along with // this program. If not, see . -use anyhow::{anyhow, Result as AnyResult}; +use anyhow::{Result as AnyResult, anyhow}; use std::{ collections::{BTreeMap, HashSet, VecDeque}, env::var_os, - fs::{read_to_string, File}, + fs::{File, read_to_string}, io::{Error as IoError, Write}, path::{Path, PathBuf}, }; @@ -197,9 +197,11 @@ fn main() -> AnyResult<()> { (99998, Source::Codepage, "replacement"), (99999, Source::Codepage, "x-user-defined"), ] { - assert!(codepages - .insert(codepage, [(source, vec![name])].into_iter().collect()) - .is_none()); + assert!( + codepages + .insert(codepage, [(source, vec![name])].into_iter().collect()) + .is_none() + ); } let output_file_name = Path::new(&var_os("OUT_DIR").unwrap()).join("encodings.rs"); diff --git a/rust/pspp/src/command.rs b/rust/pspp/src/command.rs index 5f0d1ec55b..471bb84485 100644 --- a/rust/pspp/src/command.rs +++ b/rust/pspp/src/command.rs @@ -26,7 +26,7 @@ use ctables::ctables_command; use data_list::data_list_command; use descriptives::descriptives_command; use either::Either; -use flagset::{flags, FlagSet}; +use flagset::{FlagSet, flags}; use pspp_derive::FromTokens; use crate::{ @@ -34,9 +34,9 @@ use crate::{ identifier::Identifier, integer::ToInteger, lex::{ + Punct, Token, command_name::CommandMatcher, lexer::{LexToken, TokenSlice}, - Punct, Token, }, message::{Diagnostic, Diagnostics}, }; diff --git a/rust/pspp/src/command/ctables.rs b/rust/pspp/src/command/ctables.rs index fd65961523..a42e9fcd2d 100644 --- a/rust/pspp/src/command/ctables.rs +++ b/rust/pspp/src/command/ctables.rs @@ -161,12 +161,12 @@ struct Expression(MulExpression, Seq0<(Either, Expression)>); impl Debug for Expression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.1 .0.is_empty() { + if self.1.0.is_empty() { self.0.fmt(f) } else { write!(f, "(")?; self.0.fmt(f)?; - for (operator, operand) in &self.1 .0 { + for (operator, operand) in &self.1.0 { if operator.is_left() { write!(f, " + ")?; } else { @@ -187,12 +187,12 @@ struct MulExpression( impl Debug for MulExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.1 .0.is_empty() { + if self.1.0.is_empty() { self.0.fmt(f) } else { write!(f, "(")?; self.0.fmt(f)?; - for (operator, operand) in &self.1 .0 { + for (operator, operand) in &self.1.0 { if operator.is_left() { write!(f, " * ")?; } else { @@ -210,12 +210,12 @@ struct PowExpression(Terminal, Seq0<(Exp, PowExpression)>); impl Debug for PowExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.1 .0.is_empty() { + if self.1.0.is_empty() { self.0.fmt(f) } else { write!(f, "(")?; self.0.fmt(f)?; - for (_operator, operand) in &self.1 .0 { + for (_operator, operand) in &self.1.0 { write!(f, " ** {operand:?}")?; } write!(f, ")") diff --git a/rust/pspp/src/convert.rs b/rust/pspp/src/convert.rs index aa59cbfa42..34aed906bb 100644 --- a/rust/pspp/src/convert.rs +++ b/rust/pspp/src/convert.rs @@ -16,11 +16,11 @@ use std::{ fs::File, - io::{stdout, Write}, + io::{Write, stdout}, path::{Path, PathBuf}, }; -use anyhow::{anyhow, bail, Error as AnyError, Result}; +use anyhow::{Error as AnyError, Result, anyhow, bail}; use chrono::{Datelike, NaiveTime, Timelike}; use clap::{Args, ValueEnum}; use csv::Writer; @@ -31,7 +31,7 @@ use pspp::{ file::FileType, format::{DisplayPlain, Type}, por::PortableFile, - sys::{raw::records::Compression, ReadOptions, WriteOptions}, + sys::{ReadOptions, WriteOptions, raw::records::Compression}, util::ToSmallString, variable::Variable, }; diff --git a/rust/pspp/src/crypto.rs b/rust/pspp/src/crypto.rs index 0d1282f74c..cce9825632 100644 --- a/rust/pspp/src/crypto.rs +++ b/rust/pspp/src/crypto.rs @@ -12,8 +12,8 @@ #![cfg_attr(not(test), warn(missing_docs))] use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, KeyInit}, Aes256, Aes256Dec, + cipher::{BlockDecrypt, KeyInit, generic_array::GenericArray}, }; use cmac::{Cmac, Mac}; use smallvec::SmallVec; @@ -23,7 +23,7 @@ use std::{ }; use thiserror::Error as ThisError; -use binrw::{io::NoSeek, BinRead}; +use binrw::{BinRead, io::NoSeek}; /// Error reading an encrypted file. #[derive(Clone, Debug, ThisError)] @@ -130,7 +130,7 @@ where _ => { return Err(Error::UnknownFileType( header.file_type.iter().map(|b| *b as char).collect(), - )) + )); } }; let mut first_block = [0; 16]; diff --git a/rust/pspp/src/data.rs b/rust/pspp/src/data.rs index ebacd6108e..5552b813f5 100644 --- a/rust/pspp/src/data.rs +++ b/rust/pspp/src/data.rs @@ -35,20 +35,20 @@ use std::{ str::from_utf8, }; -use encoding_rs::{mem::decode_latin1, Encoding, UTF_8}; +use encoding_rs::{Encoding, UTF_8, mem::decode_latin1}; use itertools::Itertools; use ordered_float::OrderedFloat; use serde::{ - ser::{SerializeSeq, SerializeTupleVariant}, Serialize, + ser::{SerializeSeq, SerializeTupleVariant}, }; use crate::{ dictionary::Dictionary, format::DisplayPlain, output::{ - pivot::{Axis3, Dimension, Group, PivotTable, Value}, Item, Text, + pivot::{Axis3, Dimension, Group, PivotTable, Value}, }, variable::{VarType, VarWidth}, }; diff --git a/rust/pspp/src/decrypt.rs b/rust/pspp/src/decrypt.rs index 5500b0093d..50e0629cae 100644 --- a/rust/pspp/src/decrypt.rs +++ b/rust/pspp/src/decrypt.rs @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use clap::Args; use pspp::crypto::EncryptedFile; use std::{fs::File, path::PathBuf}; diff --git a/rust/pspp/src/dictionary.rs b/rust/pspp/src/dictionary.rs index 7a0088a47e..1f30563655 100644 --- a/rust/pspp/src/dictionary.rs +++ b/rust/pspp/src/dictionary.rs @@ -19,7 +19,7 @@ use core::str; use std::{ borrow::Cow, - collections::{btree_set, BTreeSet, HashSet}, + collections::{BTreeSet, HashSet, btree_set}, ops::{Bound, Index, RangeBounds, RangeInclusive}, }; @@ -27,8 +27,8 @@ use encoding_rs::{Encoding, UTF_8}; use enum_map::{Enum, EnumMap}; use indexmap::IndexSet; use serde::{ - ser::{SerializeMap, SerializeSeq, SerializeStruct}, Serialize, + ser::{SerializeMap, SerializeSeq, SerializeStruct}, }; use smallvec::SmallVec; use thiserror::Error as ThisError; @@ -275,10 +275,11 @@ impl Dictionary { } pub fn add_variable_set(&mut self, set: DictIndexVariableSet) { - assert!(set - .variables - .iter() - .all(|dict_index| *dict_index < self.variables.len())); + assert!( + set.variables + .iter() + .all(|dict_index| *dict_index < self.variables.len()) + ); self.variable_sets.push(set); } @@ -1412,7 +1413,9 @@ pub enum MrSetError { /// Counted value {value} has width {width}, but it must be no wider than /// {max_width}, the width of the narrowest variable in multiple response /// set {mr_set}. - #[error("Counted value {value} has width {width}, but it must be no wider than {max_width}, the width of the narrowest variable in multiple response set {mr_set}.")] + #[error( + "Counted value {value} has width {width}, but it must be no wider than {max_width}, the width of the narrowest variable in multiple response set {mr_set}." + )] TooWideMDGroupCountedValue { /// Multiple response set name. mr_set: Identifier, diff --git a/rust/pspp/src/format.rs b/rust/pspp/src/format.rs index 401b22f0fa..e9d26895e0 100644 --- a/rust/pspp/src/format.rs +++ b/rust/pspp/src/format.rs @@ -22,7 +22,7 @@ use std::{ }; use chrono::{Datelike, Local}; -use enum_iterator::{all, Sequence}; +use enum_iterator::{Sequence, all}; use enum_map::{Enum, EnumMap}; use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; @@ -68,7 +68,9 @@ pub enum Error { #[error("Numeric variable is not compatible with string format {0}.")] UnnamedVariableNotCompatibleWithStringFormat(Type), - #[error("String variable {variable} with width {width} is not compatible with format {bad_spec}. Use format {good_spec} instead.")] + #[error( + "String variable {variable} with width {width} is not compatible with format {bad_spec}. Use format {good_spec} instead." + )] NamedStringVariableBadSpecWidth { variable: String, width: Width, @@ -76,7 +78,9 @@ pub enum Error { good_spec: Format, }, - #[error("String variable with width {width} is not compatible with format {bad_spec}. Use format {good_spec} instead.")] + #[error( + "String variable with width {width} is not compatible with format {bad_spec}. Use format {good_spec} instead." + )] UnnamedStringVariableBadSpecWidth { width: Width, bad_spec: Format, diff --git a/rust/pspp/src/format/display/tests.rs b/rust/pspp/src/format/display/tests.rs index 9ddd3047f2..e0bbf84cc9 100644 --- a/rust/pspp/src/format/display/tests.rs +++ b/rust/pspp/src/format/display/tests.rs @@ -16,7 +16,7 @@ use std::{fmt::Write, fs::File, io::BufRead, path::Path}; -use binrw::{io::BufReader, Endian}; +use binrw::{Endian, io::BufReader}; use encoding_rs::UTF_8; use itertools::Itertools; use smallstr::SmallString; @@ -24,8 +24,8 @@ use smallvec::SmallVec; use crate::{ data::{ByteString, Datum, WithEncoding}, - format::{AbstractFormat, Epoch, Format, Settings, Type, UncheckedFormat, CC}, - lex::{scan::StringScanner, segment::Syntax, Punct, Token}, + format::{AbstractFormat, CC, Epoch, Format, Settings, Type, UncheckedFormat}, + lex::{Punct, Token, scan::StringScanner, segment::Syntax}, settings::EndianSettings, }; @@ -1294,10 +1294,10 @@ fn test_times(format: Format, name: &str) { .display(format) .to_string(); assert!( - formatted == expect, - "formatting {}:{line_number} as {format}:\n actual: {formatted:?}\nexpected: {expect:?}", - input_filename.display() - ); + formatted == expect, + "formatting {}:{line_number} as {format}:\n actual: {formatted:?}\nexpected: {expect:?}", + input_filename.display() + ); } } diff --git a/rust/pspp/src/format/parse.rs b/rust/pspp/src/format/parse.rs index 2161e3dc0a..45b37b57bc 100644 --- a/rust/pspp/src/format/parse.rs +++ b/rust/pspp/src/format/parse.rs @@ -15,7 +15,7 @@ // this program. If not, see . use crate::{ - calendar::{calendar_gregorian_to_offset, DateError}, + calendar::{DateError, calendar_gregorian_to_offset}, data::{ByteString, Datum, EncodedString, OwnedDatum, RawString, WithEncoding}, endian::FromBytes, format::{DateTemplate, Decimals, Settings, TemplateItem, Type}, @@ -106,7 +106,9 @@ enum ParseErrorKind { InvalidWeek(i32), /// Unrecognized month format. - #[error("Unrecognized month format. Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.")] + #[error( + "Unrecognized month format. Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names." + )] InvalidMonth, /// Delimiter expected between fields in time. @@ -122,7 +124,9 @@ enum ParseErrorKind { InvalidMinute(i32), /// Invalid weekday name. - #[error("Unrecognized weekday name. At least the first two letters of an English weekday name must be specified.")] + #[error( + "Unrecognized weekday name. At least the first two letters of an English weekday name must be specified." + )] InvalidWeekdayName, /// Expected character. @@ -925,8 +929,8 @@ mod tests { calendar::{days_in_month, is_leap_year}, data::{ByteStr, Datum, EncodedString, OwnedDatum, RawString}, format::{ - parse::{ParseError, ParseErrorKind, Sign}, Epoch, Format, Settings as FormatSettings, Type, + parse::{ParseError, ParseErrorKind, Sign}, }, settings::EndianSettings, }; diff --git a/rust/pspp/src/identifier.rs b/rust/pspp/src/identifier.rs index 700b1cd087..5422c534c1 100644 --- a/rust/pspp/src/identifier.rs +++ b/rust/pspp/src/identifier.rs @@ -126,7 +126,9 @@ pub enum Error { #[error("\"!\" is not a valid identifier.")] Bang, - #[error("{string:?} may not be used as an identifier because it begins with disallowed character {c:?}.")] + #[error( + "{string:?} may not be used as an identifier because it begins with disallowed character {c:?}." + )] BadFirstCharacter { string: String, c: char }, #[error( @@ -134,7 +136,9 @@ pub enum Error { )] BadLaterCharacter { string: String, c: char }, - #[error("Identifier \"{id}\" is {length} bytes in the encoding in use ({encoding}), which exceeds the {max}-byte limit.")] + #[error( + "Identifier \"{id}\" is {length} bytes in the encoding in use ({encoding}), which exceeds the {max}-byte limit." + )] TooLong { id: String, length: usize, @@ -142,7 +146,9 @@ pub enum Error { max: usize, }, - #[error("\"{id}\" may not be used as an identifier because the encoding in use ({encoding}) cannot represent \"{c}\".")] + #[error( + "\"{id}\" may not be used as an identifier because the encoding in use ({encoding}) cannot represent \"{c}\"." + )] NotEncodable { id: String, encoding: &'static str, diff --git a/rust/pspp/src/lex/lexer.rs b/rust/pspp/src/lex/lexer.rs index 62a30b0d1e..319ff36d00 100644 --- a/rust/pspp/src/lex/lexer.rs +++ b/rust/pspp/src/lex/lexer.rs @@ -36,7 +36,7 @@ use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; use crate::{ lex::scan::merge_tokens, - macros::{macro_tokens_to_syntax, MacroSet, ParseStatus, Parser}, + macros::{MacroSet, ParseStatus, Parser, macro_tokens_to_syntax}, message::{Category, Diagnostic, Location, Point, Severity}, settings::Settings, }; diff --git a/rust/pspp/src/lex/segment.rs b/rust/pspp/src/lex/segment.rs index 27313a7184..625fbd9a1a 100644 --- a/rust/pspp/src/lex/segment.rs +++ b/rust/pspp/src/lex/segment.rs @@ -39,12 +39,12 @@ use std::cmp::Ordering; use crate::{ - identifier::{id_match, id_match_n, IdentifierChar}, + identifier::{IdentifierChar, id_match, id_match_n}, prompt::PromptStyle, }; use bitflags::bitflags; -use super::command_name::{command_match, COMMAND_NAMES}; +use super::command_name::{COMMAND_NAMES, command_match}; /// Syntax variant. /// @@ -1286,7 +1286,7 @@ impl Segmenter { }; match c { '!' if strip_prefix_ignore_ascii_case(input, "!ENDDEFINE").is_some() => { - return Some(input) + return Some(input); } '\'' | '"' => { let index = rest.find(c)?; diff --git a/rust/pspp/src/locale_charset.rs b/rust/pspp/src/locale_charset.rs index 26856ef803..534d0e7297 100644 --- a/rust/pspp/src/locale_charset.rs +++ b/rust/pspp/src/locale_charset.rs @@ -221,11 +221,11 @@ fn map_aliases(s: &str) -> &'static str { #[cfg(unix)] mod inner { use std::{ - ffi::{c_int, CStr, CString}, + ffi::{CStr, CString, c_int}, ptr::null, }; - use libc::{self, nl_langinfo, setlocale, CODESET, LC_CTYPE}; + use libc::{self, CODESET, LC_CTYPE, nl_langinfo, setlocale}; unsafe fn string_from_pointer(s: *const i8) -> Option { if s.is_null() { @@ -256,7 +256,7 @@ mod inner { #[cfg(windows)] mod inner { - use libc::{setlocale, LC_CTYPE}; + use libc::{LC_CTYPE, setlocale}; use std::ffi::{CStr, CString}; use windows_sys::Win32::Globalization::GetACP; diff --git a/rust/pspp/src/macros.rs b/rust/pspp/src/macros.rs index c5d9c9e94f..5107842e4b 100644 --- a/rust/pspp/src/macros.rs +++ b/rust/pspp/src/macros.rs @@ -31,9 +31,9 @@ use unicase::UniCase; use crate::{ identifier::Identifier, lex::{ + Punct, Token, scan::{ScanError, StringScanner, StringSegmenter}, segment::Syntax, - Punct, Token, }, message::Location, settings::Settings, @@ -134,11 +134,15 @@ pub enum MacroError { BadNumericMacroExpression(String), /// Too many iteration for list-based loop. - #[error("`!DO` loop over list exceeded maximum number of iterations {0}. (Use `SET MITERATE` to change the limit.)")] + #[error( + "`!DO` loop over list exceeded maximum number of iterations {0}. (Use `SET MITERATE` to change the limit.)" + )] MiterateList(usize), /// Too many iteration for numerical loop. - #[error("Numerical `!DO` loop exceeded maximum number of iterations {0}. (Use `SET MITERATE` to change the limit.)")] + #[error( + "Numerical `!DO` loop exceeded maximum number of iterations {0}. (Use `SET MITERATE` to change the limit.)" + )] MiterateNumeric(usize), /// Expecting `!TO` in numerical `!DO` loop. diff --git a/rust/pspp/src/output/cairo/driver.rs b/rust/pspp/src/output/cairo/driver.rs index fbcabc06c0..e239298110 100644 --- a/rust/pspp/src/output/cairo/driver.rs +++ b/rust/pspp/src/output/cairo/driver.rs @@ -21,19 +21,19 @@ use std::{ }; use cairo::{Context, PdfSurface}; -use enum_map::{enum_map, EnumMap}; +use enum_map::{EnumMap, enum_map}; use pango::SCALE; use serde::{Deserialize, Serialize}; use crate::output::{ + Item, cairo::{ - fsm::{parse_font_style, CairoFsmStyle}, + fsm::{CairoFsmStyle, parse_font_style}, pager::{CairoPageStyle, CairoPager}, }, driver::Driver, page::PageSetup, pivot::{Color, Coord2, FontStyle}, - Item, }; use crate::output::pivot::Axis2; diff --git a/rust/pspp/src/output/cairo/fsm.rs b/rust/pspp/src/output/cairo/fsm.rs index ccf4d21f1c..13597f30a0 100644 --- a/rust/pspp/src/output/cairo/fsm.rs +++ b/rust/pspp/src/output/cairo/fsm.rs @@ -17,21 +17,21 @@ use std::{cmp::min, f64::consts::PI, fmt::Write, ops::DerefMut, sync::Arc}; use cairo::Context; -use enum_map::{enum_map, EnumMap}; +use enum_map::{EnumMap, enum_map}; use itertools::Itertools; use pango::{ - parse_markup, AttrFloat, AttrFontDesc, AttrInt, AttrList, Attribute, FontDescription, FontMask, - Layout, Underline, Weight, SCALE, SCALE_SMALL, + AttrFloat, AttrFontDesc, AttrInt, AttrList, Attribute, FontDescription, FontMask, Layout, + SCALE, SCALE_SMALL, Underline, Weight, parse_markup, }; use pangocairo::functions::show_layout; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use crate::output::cairo::{horz_align_to_pango, px_to_xr, xr_to_pt}; use crate::output::pivot::{Axis2, BorderStyle, Coord2, FontStyle, HorzAlign, Rect2, Stroke}; use crate::output::render::{Device, Extreme, Pager, Params}; use crate::output::table::DrawCell; -use crate::output::{pivot::Color, table::Content}; use crate::output::{Details, Item}; +use crate::output::{pivot::Color, table::Content}; /// Width of an ordinary line. const LINE_WIDTH: usize = LINE_SPACE / 2; diff --git a/rust/pspp/src/output/cairo/pager.rs b/rust/pspp/src/output/cairo/pager.rs index d490fc696b..6106eb6a0e 100644 --- a/rust/pspp/src/output/cairo/pager.rs +++ b/rust/pspp/src/output/cairo/pager.rs @@ -21,13 +21,13 @@ use enum_map::EnumMap; use pango::{FontDescription, Layout}; use crate::output::{ + Item, ItemCursor, cairo::{ fsm::{CairoFsm, CairoFsmStyle}, horz_align_to_pango, xr_to_pt, }, page::Heading, pivot::Axis2, - Item, ItemCursor, }; #[derive(Clone, Debug)] diff --git a/rust/pspp/src/output/csv.rs b/rust/pspp/src/output/csv.rs index 0626d90eb2..0eded20bdb 100644 --- a/rust/pspp/src/output/csv.rs +++ b/rust/pspp/src/output/csv.rs @@ -24,13 +24,13 @@ use std::{ }; use serde::{ - de::{Unexpected, Visitor}, Deserialize, Deserializer, Serialize, + de::{Unexpected, Visitor}, }; use crate::output::pivot::Coord2; -use super::{driver::Driver, pivot::PivotTable, table::Table, Details, Item, TextType}; +use super::{Details, Item, TextType, driver::Driver, pivot::PivotTable, table::Table}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CsvConfig { diff --git a/rust/pspp/src/output/driver.rs b/rust/pspp/src/output/driver.rs index 5d97660126..6015ed8284 100644 --- a/rust/pspp/src/output/driver.rs +++ b/rust/pspp/src/output/driver.rs @@ -28,7 +28,7 @@ use crate::output::{ text::{TextConfig, TextDriver}, }; -use super::{page::PageSetup, Item}; +use super::{Item, page::PageSetup}; // An output driver. pub trait Driver { diff --git a/rust/pspp/src/output/html.rs b/rust/pspp/src/output/html.rs index cfc515d19a..949724b9af 100644 --- a/rust/pspp/src/output/html.rs +++ b/rust/pspp/src/output/html.rs @@ -27,10 +27,10 @@ use serde::{Deserialize, Serialize}; use smallstr::SmallString; use crate::output::{ + Details, Item, driver::Driver, pivot::{Axis2, BorderStyle, Color, Coord2, HorzAlign, PivotTable, Rect2, Stroke, VertAlign}, table::{DrawCell, Table}, - Details, Item, }; #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/rust/pspp/src/output/json.rs b/rust/pspp/src/output/json.rs index af6923d390..c7f52bd5e7 100644 --- a/rust/pspp/src/output/json.rs +++ b/rust/pspp/src/output/json.rs @@ -24,7 +24,7 @@ use std::{ use serde::{Deserialize, Serialize}; -use super::{driver::Driver, Item}; +use super::{Item, driver::Driver}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct JsonConfig { diff --git a/rust/pspp/src/output/page.rs b/rust/pspp/src/output/page.rs index 4240b8d9f5..6872a6aeab 100644 --- a/rust/pspp/src/output/page.rs +++ b/rust/pspp/src/output/page.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // this program. If not, see . -use enum_map::{enum_map, EnumMap}; +use enum_map::{EnumMap, enum_map}; use serde::{Deserialize, Serialize}; use super::pivot::{Axis2, HorzAlign}; diff --git a/rust/pspp/src/output/pivot.rs b/rust/pspp/src/output/pivot.rs index c909d8dd38..5ceab55e8e 100644 --- a/rust/pspp/src/output/pivot.rs +++ b/rust/pspp/src/output/pivot.rs @@ -46,24 +46,24 @@ use std::{ collections::HashMap, fmt::{Debug, Display, Write}, io::Read, - iter::{once, repeat, repeat_n, FusedIterator}, + iter::{FusedIterator, once, repeat, repeat_n}, ops::{Index, IndexMut, Not, Range, RangeInclusive}, - str::{from_utf8, FromStr, Utf8Error}, + str::{FromStr, Utf8Error, from_utf8}, sync::{Arc, OnceLock}, }; use binrw::Error as BinError; use chrono::NaiveDateTime; pub use color::ParseError as ParseColorError; -use color::{palette::css::TRANSPARENT, AlphaColor, Rgba8, Srgb}; +use color::{AlphaColor, Rgba8, Srgb, palette::css::TRANSPARENT}; use enum_iterator::Sequence; -use enum_map::{enum_map, Enum, EnumMap}; +use enum_map::{Enum, EnumMap, enum_map}; use look_xml::TableProperties; -use quick_xml::{de::from_str, DeError}; +use quick_xml::{DeError, de::from_str}; use serde::{ + Deserialize, Serialize, Serializer, de::Visitor, ser::{SerializeMap, SerializeStruct}, - Deserialize, Serialize, Serializer, }; use smallstr::SmallString; use smallvec::SmallVec; diff --git a/rust/pspp/src/output/pivot/look_xml.rs b/rust/pspp/src/output/pivot/look_xml.rs index c935125e31..a9e1264f55 100644 --- a/rust/pspp/src/output/pivot/look_xml.rs +++ b/rust/pspp/src/output/pivot/look_xml.rs @@ -17,7 +17,7 @@ use std::{fmt::Debug, num::ParseFloatError, str::FromStr}; use enum_map::enum_map; -use serde::{de::Visitor, Deserialize}; +use serde::{Deserialize, de::Visitor}; use crate::{ format::Decimal, diff --git a/rust/pspp/src/output/pivot/output.rs b/rust/pspp/src/output/pivot/output.rs index 3a6f24cbeb..8df1ae5369 100644 --- a/rust/pspp/src/output/pivot/output.rs +++ b/rust/pspp/src/output/pivot/output.rs @@ -16,7 +16,7 @@ use std::{iter::zip, ops::Range, sync::Arc}; -use enum_map::{enum_map, EnumMap}; +use enum_map::{EnumMap, enum_map}; use itertools::Itertools; use crate::output::{ diff --git a/rust/pspp/src/output/pivot/tests.rs b/rust/pspp/src/output/pivot/tests.rs index a69f821532..27c3f1975d 100644 --- a/rust/pspp/src/output/pivot/tests.rs +++ b/rust/pspp/src/output/pivot/tests.rs @@ -19,6 +19,7 @@ use std::{fmt::Display, fs::File, path::Path, sync::Arc}; use enum_map::EnumMap; use crate::output::{ + Details, Item, cairo::{CairoConfig, CairoDriver}, driver::Driver, html::HtmlDriver, @@ -28,7 +29,6 @@ use crate::output::{ Look, PivotTable, RowColBorder, Stroke, }, spv::SpvDriver, - Details, Item, }; use super::{Axis3, Value}; diff --git a/rust/pspp/src/output/pivot/tlo.rs b/rust/pspp/src/output/pivot/tlo.rs index dfa292c911..e857784809 100644 --- a/rust/pspp/src/output/pivot/tlo.rs +++ b/rust/pspp/src/output/pivot/tlo.rs @@ -25,7 +25,7 @@ use crate::{ }; use super::{Area, BorderStyle, Color, HorzAlign, Look, Stroke, VertAlign}; -use binrw::{binread, BinRead, BinResult, Error as BinError}; +use binrw::{BinRead, BinResult, Error as BinError, binread}; use enum_map::enum_map; #[binread] diff --git a/rust/pspp/src/output/render.rs b/rust/pspp/src/output/render.rs index 075a1fa69f..61ac68af47 100644 --- a/rust/pspp/src/output/render.rs +++ b/rust/pspp/src/output/render.rs @@ -20,7 +20,7 @@ use std::iter::once; use std::ops::Range; use std::sync::Arc; -use enum_map::{enum_map, Enum, EnumMap}; +use enum_map::{Enum, EnumMap, enum_map}; use itertools::interleave; use num::Integer; use smallvec::SmallVec; @@ -777,9 +777,11 @@ impl Page { overflow[a][1] += pixel1 + self.axis_width(a, cell_ofs(z1)..cell_ofs(cell.rect[a].end)); } - assert!(overflows - .insert(s.coord_to_subpage(cell.rect.top_left()), overflow) - .is_none()); + assert!( + overflows + .insert(s.coord_to_subpage(cell.rect.top_left()), overflow) + .is_none() + ); } z += cell.rect[b].len(); } @@ -796,9 +798,11 @@ impl Page { let mut overflow = self.overflows.get(&d).cloned().unwrap_or_default(); overflow[a][1] += pixel1 + self.axis_width(a, cell_ofs(z1)..cell_ofs(cell.rect[a].end)); - assert!(overflows - .insert(s.coord_to_subpage(cell.rect.top_left()), overflow) - .is_none()); + assert!( + overflows + .insert(s.coord_to_subpage(cell.rect.top_left()), overflow) + .is_none() + ); } z += cell.rect[b].len(); } @@ -1130,11 +1134,7 @@ fn measure_rule(device: &dyn Device, table: &Table, a: Axis2, z: usize) -> usize .into_iter() .map( |(rule, present)| { - if present { - line_widths[rule] - } else { - 0 - } + if present { line_widths[rule] } else { 0 } }, ) .max() diff --git a/rust/pspp/src/output/spv.rs b/rust/pspp/src/output/spv.rs index 89ae457544..9f7290f1b3 100644 --- a/rust/pspp/src/output/spv.rs +++ b/rust/pspp/src/output/spv.rs @@ -28,16 +28,17 @@ use binrw::{BinWrite, Endian}; use chrono::Utc; use enum_map::EnumMap; use quick_xml::{ - events::{attributes::Attribute, BytesText}, - writer::Writer as XmlWriter, ElementWriter, + events::{BytesText, attributes::Attribute}, + writer::Writer as XmlWriter, }; use serde::{Deserialize, Serialize}; -use zip::{result::ZipResult, write::SimpleFileOptions, ZipWriter}; +use zip::{ZipWriter, result::ZipResult, write::SimpleFileOptions}; use crate::{ format::{Format, Type}, output::{ + Item, Text, driver::Driver, page::{Heading, PageSetup}, pivot::{ @@ -46,7 +47,6 @@ use crate::{ Footnotes, Group, HeadingRegion, HorzAlign, LabelPosition, Leaf, PivotTable, RowColBorder, Stroke, Value, ValueInner, ValueStyle, VertAlign, }, - Item, Text, }, settings::Show, util::ToSmallString, diff --git a/rust/pspp/src/output/table.rs b/rust/pspp/src/output/table.rs index d9ef87f624..98d5a0b16f 100644 --- a/rust/pspp/src/output/table.rs +++ b/rust/pspp/src/output/table.rs @@ -28,7 +28,7 @@ use std::{ops::Range, sync::Arc}; -use enum_map::{enum_map, EnumMap}; +use enum_map::{EnumMap, enum_map}; use ndarray::{Array, Array2}; use crate::output::pivot::{Coord2, DisplayValue, Footnote, HorzAlign, ValueInner}; diff --git a/rust/pspp/src/output/text.rs b/rust/pspp/src/output/text.rs index 147f475d53..990f1fae7a 100644 --- a/rust/pspp/src/output/text.rs +++ b/rust/pspp/src/output/text.rs @@ -24,20 +24,20 @@ use std::{ sync::{Arc, LazyLock}, }; -use enum_map::{enum_map, Enum, EnumMap}; +use enum_map::{Enum, EnumMap, enum_map}; use serde::{Deserialize, Serialize}; -use unicode_linebreak::{linebreaks, BreakOpportunity}; +use unicode_linebreak::{BreakOpportunity, linebreaks}; use unicode_width::UnicodeWidthStr; use crate::output::{render::Extreme, table::DrawCell, text_line::Emphasis}; use super::{ + Details, Item, driver::Driver, pivot::{Axis2, BorderStyle, Coord2, HorzAlign, PivotTable, Rect2, Stroke}, render::{Device, Pager, Params}, table::Content, - text_line::{clip_text, TextLine}, - Details, Item, + text_line::{TextLine, clip_text}, }; #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -672,7 +672,9 @@ mod tests { fn test_line_breaks(input: &str, width: usize, expected: Vec<&str>) { let actual = new_line_breaks(input, width).collect::>(); if expected != actual { - panic!("filling {input:?} to {width} columns:\nexpected: {expected:?}\nactual: {actual:?}"); + panic!( + "filling {input:?} to {width} columns:\nexpected: {expected:?}\nactual: {actual:?}" + ); } } #[test] diff --git a/rust/pspp/src/por/read.rs b/rust/pspp/src/por/read.rs index ac726cae46..51ccfbef8e 100644 --- a/rust/pspp/src/por/read.rs +++ b/rust/pspp/src/por/read.rs @@ -28,7 +28,7 @@ use codepage_437::CP437_WINGDINGS; use encoding_rs::WINDOWS_1252; use indexmap::set::MutableValues; use num::{Bounded, NumCast}; -use serde::{ser::SerializeSeq, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeSeq}; use crate::{ data::{ByteString, Case, Datum, RawString, WithEncoding}, @@ -1158,8 +1158,8 @@ mod tests { use crate::{ data::cases_to_output, output::{ - pivot::{tests::assert_lines_eq, PivotTable}, Details, Item, Text, + pivot::{PivotTable, tests::assert_lines_eq}, }, por::{PortableFile, ReadPad}, }; @@ -1170,7 +1170,10 @@ mod tests { b"abcdefghijklmnop\r\n0123456789\r\n", ))) .lines(); - assert_eq!(lines.next().unwrap().unwrap(), "abcdefghijklmnop 0123456789 "); + assert_eq!( + lines.next().unwrap().unwrap(), + "abcdefghijklmnop 0123456789 " + ); } fn test_porfile(name: &str) { diff --git a/rust/pspp/src/por/write.rs b/rust/pspp/src/por/write.rs index 15aad13820..c5150c96ab 100644 --- a/rust/pspp/src/por/write.rs +++ b/rust/pspp/src/por/write.rs @@ -295,11 +295,7 @@ where { fn write(&mut self, buf: &[u8]) -> std::io::Result { fn handle_error(error: std::io::Error, ofs: usize) -> std::io::Result { - if ofs > 0 { - Ok(ofs) - } else { - Err(error) - } + if ofs > 0 { Ok(ofs) } else { Err(error) } } fn write_chunk(mut writer: W, chunk: &[u8]) -> std::io::Result @@ -831,15 +827,15 @@ mod tests { use encoding_rs::{UTF_8, WINDOWS_1252}; use indexmap::set::MutableValues; - use itertools::{zip_eq, Itertools}; + use itertools::{Itertools, zip_eq}; use crate::{ data::{ByteString, Datum, RawString}, dictionary::Dictionary, identifier::Identifier, por::{ - write::{write_case, DictionaryWriter, Precision, TrigesimalFloat, TrigesimalInt}, WriteOptions, + write::{DictionaryWriter, Precision, TrigesimalFloat, TrigesimalInt, write_case}, }, variable::{MissingValueRange, MissingValues, VarWidth, Variable}, }; @@ -1242,12 +1238,20 @@ A1/\ output.sort(); let expected = [ - ("1/4/VAR01/", vec!["1/3/One"]), - ("1/4/VAR31/", vec!["4/abcd3/One"]), - ("1/4/VAR41/", vec!["8/abcdefghI/Longer value label"]), - ("1/4/VAR51/", vec!["9/abcdefghiS/value label for 9-byte value"]), - ("1/4/VAR61/", vec!["A0/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx10/value label for 300-byte value"]), - ("2/4/VAR14/VAR22/", vec!["1/3/One", "2/3/Two"]), + ("1/4/VAR01/", vec!["1/3/One"]), + ("1/4/VAR31/", vec!["4/abcd3/One"]), + ("1/4/VAR41/", vec!["8/abcdefghI/Longer value label"]), + ( + "1/4/VAR51/", + vec!["9/abcdefghiS/value label for 9-byte value"], + ), + ( + "1/4/VAR61/", + vec![ + "A0/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx10/value label for 300-byte value", + ], + ), + ("2/4/VAR14/VAR22/", vec!["1/3/One", "2/3/Two"]), ]; for (actual, (exp_prefix, exp_suffixes)) in zip_eq(output, expected) { diff --git a/rust/pspp/src/show.rs b/rust/pspp/src/show.rs index 699425e85c..2a866c5d47 100644 --- a/rust/pspp/src/show.rs +++ b/rust/pspp/src/show.rs @@ -15,19 +15,19 @@ // this program. If not, see . use crate::parse_encoding; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use clap::{Args, ValueEnum}; use encoding_rs::Encoding; use pspp::{ data::cases_to_output, output::{ + Details, Item, Text, driver::{Config, Driver}, pivot::PivotTable, - Details, Item, Text, }, sys::{ - raw::{infer_encoding, Decoder, EncodingReport, Magic, Reader, Record}, Records, + raw::{Decoder, EncodingReport, Magic, Reader, Record, infer_encoding}, }, }; use serde::Serialize; @@ -36,7 +36,7 @@ use std::{ ffi::OsStr, fmt::{Display, Write as _}, fs::File, - io::{stdout, BufReader, Write}, + io::{BufReader, Write, stdout}, path::{Path, PathBuf}, rc::Rc, sync::Arc, diff --git a/rust/pspp/src/show_por.rs b/rust/pspp/src/show_por.rs index 28529e2315..d0ba365eca 100644 --- a/rust/pspp/src/show_por.rs +++ b/rust/pspp/src/show_por.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License along with // this program. If not, see . -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use clap::{Args, ValueEnum}; use pspp::{ data::cases_to_output, output::{ + Details, Item, Text, driver::{Config, Driver}, pivot::PivotTable, - Details, Item, Text, }, por::PortableFile, }; @@ -31,7 +31,7 @@ use std::{ ffi::OsStr, fmt::{Display, Write as _}, fs::File, - io::{stdout, BufReader, Write}, + io::{BufReader, Write, stdout}, path::{Path, PathBuf}, rc::Rc, sync::Arc, diff --git a/rust/pspp/src/sys/cooked.rs b/rust/pspp/src/sys/cooked.rs index 78440d801c..7316d29b9d 100644 --- a/rust/pspp/src/sys/cooked.rs +++ b/rust/pspp/src/sys/cooked.rs @@ -36,7 +36,7 @@ use crate::{ output::pivot::{Axis3, Dimension, Group, PivotTable, Value}, sys::{ raw::{ - self, infer_encoding, + self, DecodedRecord, RawCases, RawDatum, RawWidth, Reader, infer_encoding, records::{ Compression, DocumentRecord, EncodingRecord, Extension, FileAttributesRecord, FileHeader, FloatInfoRecord, IntegerInfoRecord, LongName, LongNamesRecord, @@ -45,13 +45,12 @@ use crate::{ VarDisplayRecord, VariableAttributesRecord, VariableRecord, VariableSetRecord, VeryLongStringsRecord, }, - DecodedRecord, RawCases, RawDatum, RawWidth, Reader, }, serialize_endian, }, variable::{InvalidRole, MissingValues, MissingValuesError, VarType, VarWidth, Variable}, }; -use anyhow::{anyhow, Error as AnyError}; +use anyhow::{Error as AnyError, anyhow}; use binrw::{BinRead, BinWrite, Endian}; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use encoding_rs::{Encoding, UTF_8}; @@ -64,14 +63,18 @@ use thiserror::Error as ThisError; #[derive(ThisError, Clone, Debug)] pub enum Error { /// File creation date is not in the expected format format. - #[error("File creation date {0} is not in the expected format \"DD MMM YY\" format. Using 01 Jan 1970.")] + #[error( + "File creation date {0} is not in the expected format \"DD MMM YY\" format. Using 01 Jan 1970." + )] InvalidCreationDate( /// Date. String, ), /// File creation time is not in the expected format. - #[error("File creation time {0} is not in the expected format \"HH:MM:SS\" format. Using midnight.")] + #[error( + "File creation time {0} is not in the expected format \"HH:MM:SS\" format. Using midnight." + )] InvalidCreationTime( /// Time. String, @@ -124,7 +127,9 @@ pub enum Error { /// Variable index {start_index} is a {width} that should be followed by /// long string continuation records through index {end_index} (inclusive), /// but index {error_index} is not a continuation. - #[error("Variable index {start_index} is a {width} that should be followed by long string continuation records through index {end_index} (inclusive), but index {error_index} is not a continuation")] + #[error( + "Variable index {start_index} is a {width} that should be followed by long string continuation records through index {end_index} (inclusive), but index {error_index} is not a continuation" + )] MissingLongStringContinuation { /// Width of variable. width: RawWidth, @@ -200,9 +205,7 @@ pub enum Error { MrSetError(#[from] MrSetError), /// Invalid numeric format for counted value {number} in multiple response set {mr_set}. - #[error( - "Invalid numeric format for counted value {number} in multiple response set {mr_set}." - )] + #[error("Invalid numeric format for counted value {number} in multiple response set {mr_set}.")] InvalidMDGroupCountedValue { /// Multiple response set name. mr_set: Identifier, @@ -254,7 +257,9 @@ pub enum Error { /// Variable with short name {short_name} listed in very long string record /// with width {width}, which requires only one segment. - #[error("Variable with short name {short_name} listed in very long string record with width {width}, which requires only one segment.")] + #[error( + "Variable with short name {short_name} listed in very long string record with width {width}, which requires only one segment." + )] ShortVeryLongString { /// Short variable name. short_name: Identifier, @@ -266,7 +271,9 @@ pub enum Error { /// with width {width} requires string segments for {n_segments} dictionary /// indexes starting at index {index}, but the dictionary only contains /// {len} indexes. - #[error("Variable with short name {short_name} listed in very long string record with width {width} requires string segments for {n_segments} dictionary indexes starting at index {index}, but the dictionary only contains {len} indexes.")] + #[error( + "Variable with short name {short_name} listed in very long string record with width {width} requires string segments for {n_segments} dictionary indexes starting at index {index}, but the dictionary only contains {len} indexes." + )] VeryLongStringOverflow { /// Short variable name. short_name: Identifier, @@ -283,7 +290,9 @@ pub enum Error { /// Variable with short name {short_name} listed in very long string record /// with width {width} has segment {index} of width {actual} (expected /// {expected}). - #[error("Variable with short name {short_name} listed in very long string record with width {width} has segment {index} of width {actual} (expected {expected}).")] + #[error( + "Variable with short name {short_name} listed in very long string record with width {width} has segment {index} of width {actual} (expected {expected})." + )] VeryLongStringInvalidSegmentWidth { /// Variable short name. short_name: Identifier, @@ -306,7 +315,9 @@ pub enum Error { /// File designates string variable {name} (index {index}) as weight /// variable, but weight variables must be numeric. - #[error("File designates string variable {name} (index {index}) as weight variable, but weight variables must be numeric.")] + #[error( + "File designates string variable {name} (index {index}) as weight variable, but weight variables must be numeric." + )] InvalidWeightVar { /// Variable name. name: Identifier, @@ -373,7 +384,9 @@ pub enum Error { /// Long string missing values record says variable {name} has {count} /// missing values, but only 1 to 3 missing values are allowed. - #[error("Long string missing values record says variable {name} has {count} missing values, but only 1 to 3 missing values are allowed.")] + #[error( + "Long string missing values record says variable {name} has {count} missing values, but only 1 to 3 missing values are allowed." + )] LongStringMissingValueInvalidCount { /// Variable name. name: Identifier, @@ -391,7 +404,9 @@ pub enum Error { /// Unknown extension record with subtype {subtype} at offset {offset:#x}, /// consisting of {count} {size}-byte units. Please feel free to report /// this as a bug. - #[error("Unknown extension record with subtype {subtype} at offset {offset:#x}, consisting of {count} {size}-byte units. Please feel free to report this as a bug.")] + #[error( + "Unknown extension record with subtype {subtype} at offset {offset:#x}, consisting of {count} {size}-byte units. Please feel free to report this as a bug." + )] UnknownExtensionRecord { /// Extension record file starting offset. offset: u64, diff --git a/rust/pspp/src/sys/encoding.rs b/rust/pspp/src/sys/encoding.rs index 4e7468829b..f4ee5f3c8d 100644 --- a/rust/pspp/src/sys/encoding.rs +++ b/rust/pspp/src/sys/encoding.rs @@ -47,7 +47,9 @@ pub fn codepage_from_encoding(encoding: &'static Encoding) -> u32 { #[serde(rename_all = "snake_case")] pub enum Error { /// Warning that the system file doesn't indicate its own encoding. - #[error("This system file does not indicate its own character encoding. For best results, specify an encoding explicitly. Use SYSFILE INFO with ENCODING=\"DETECT\" to analyze the possible encodings.")] + #[error( + "This system file does not indicate its own character encoding. For best results, specify an encoding explicitly. Use SYSFILE INFO with ENCODING=\"DETECT\" to analyze the possible encodings." + )] NoEncoding, /// Unknown code page. diff --git a/rust/pspp/src/sys/raw.rs b/rust/pspp/src/sys/raw.rs index a4c9990f21..d9f770ba6a 100644 --- a/rust/pspp/src/sys/raw.rs +++ b/rust/pspp/src/sys/raw.rs @@ -24,11 +24,11 @@ use crate::{ endian::{FromBytes, ToBytes}, identifier::{Error as IdError, Identifier}, output::{ - pivot::{Axis3, Dimension, Group, PivotTable, Value}, Details, Item, Text, + pivot::{Axis3, Dimension, Group, PivotTable, Value}, }, sys::{ - encoding::{default_encoding, get_encoding, Error as EncodingError}, + encoding::{Error as EncodingError, default_encoding, get_encoding}, raw::records::{ AttributeWarning, Compression, DocumentRecord, EncodingRecord, Extension, ExtensionWarning, FileAttributesRecord, FileHeader, FloatInfoRecord, HeaderWarning, @@ -49,11 +49,11 @@ use crate::{ use binrw::Endian; use encoding_rs::{ - Encoding, BIG5, EUC_JP, EUC_KR, GB18030, IBM866, ISO_2022_JP, ISO_8859_10, ISO_8859_13, - ISO_8859_14, ISO_8859_16, ISO_8859_2, ISO_8859_3, ISO_8859_4, ISO_8859_5, ISO_8859_6, - ISO_8859_7, ISO_8859_8, KOI8_R, KOI8_U, MACINTOSH, SHIFT_JIS, UTF_8, WINDOWS_1250, - WINDOWS_1251, WINDOWS_1252, WINDOWS_1253, WINDOWS_1254, WINDOWS_1255, WINDOWS_1256, - WINDOWS_1257, WINDOWS_1258, WINDOWS_874, + BIG5, EUC_JP, EUC_KR, Encoding, GB18030, IBM866, ISO_2022_JP, ISO_8859_2, ISO_8859_3, + ISO_8859_4, ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8, ISO_8859_10, ISO_8859_13, + ISO_8859_14, ISO_8859_16, KOI8_R, KOI8_U, MACINTOSH, SHIFT_JIS, UTF_8, WINDOWS_874, + WINDOWS_1250, WINDOWS_1251, WINDOWS_1252, WINDOWS_1253, WINDOWS_1254, WINDOWS_1255, + WINDOWS_1256, WINDOWS_1257, WINDOWS_1258, }; use flate2::bufread::ZlibDecoder; use indexmap::IndexMap; @@ -65,7 +65,7 @@ use std::{ cell::RefCell, collections::VecDeque, fmt::{Debug, Display, Formatter, Result as FmtResult}, - io::{empty, BufRead, Error as IoError, Read, Seek, SeekFrom}, + io::{BufRead, Error as IoError, Read, Seek, SeekFrom, empty}, iter::repeat_n, mem::take, num::NonZeroU8, @@ -149,9 +149,7 @@ pub enum ErrorDetails { InvalidZsavCompression(u32), /// Document record has document line count ({n}) greater than the maximum number {max}. - #[error( - "Document record has document line count ({n}) greater than the maximum number {max}." - )] + #[error("Document record has document line count ({n}) greater than the maximum number {max}.")] BadDocumentLength { /// Number of document lines. n: usize, @@ -194,10 +192,9 @@ pub enum ErrorDetails { /// Following value label record, found record type {0} instead of expected /// type 4 for variable index record. - #[ - error( - "Following value label record, found record type {0} instead of expected type 4 for variable index record" - )] + #[error( + "Following value label record, found record type {0} instead of expected type 4 for variable index record" + )] ExpectedVarIndexRecord( /// Record type. u32, @@ -229,7 +226,9 @@ pub enum ErrorDetails { }, /// Unexpected end of file {case_ofs} bytes into a {case_len}-byte case. - #[error("Unexpected end of file {case_ofs} bytes into case {case_number} with expected length {case_len} bytes.")] + #[error( + "Unexpected end of file {case_ofs} bytes into case {case_number} with expected length {case_len} bytes." + )] EofInCase { /// Offset into case in bytes. case_ofs: u64, @@ -2291,7 +2290,7 @@ fn common_prefix<'a>(a: &'a str, b: &'a str) -> &'a str { } } EitherOrBoth::Left((offset, _)) | EitherOrBoth::Right((offset, _)) => { - return &a[..offset] + return &a[..offset]; } } } diff --git a/rust/pspp/src/sys/raw/records.rs b/rust/pspp/src/sys/raw/records.rs index a977eddcf4..592d29b54f 100644 --- a/rust/pspp/src/sys/raw/records.rs +++ b/rust/pspp/src/sys/raw/records.rs @@ -18,11 +18,12 @@ use crate::{ format::{DisplayPlain, Format, Type}, identifier::{Error as IdError, Identifier}, sys::{ + ProductVersion, raw::{ - read_bytes, read_string, read_vec, Decoder, Error, ErrorDetails, Magic, RawDatum, - RawWidth, Record, RecordString, UntypedDatum, VarTypes, Warning, WarningDetails, + Decoder, Error, ErrorDetails, Magic, RawDatum, RawWidth, Record, RecordString, + UntypedDatum, VarTypes, Warning, WarningDetails, read_bytes, read_string, read_vec, }, - serialize_endian, ProductVersion, + serialize_endian, }, variable::{ Alignment, Attributes, Measure, MissingValueRange, MissingValues, MissingValuesError, @@ -30,11 +31,11 @@ use crate::{ }, }; -use binrw::{binrw, BinRead, BinWrite, Endian, Error as BinError}; +use binrw::{BinRead, BinWrite, Endian, Error as BinError, binrw}; use clap::ValueEnum; use encoding_rs::Encoding; use itertools::Itertools; -use serde::{ser::SerializeTuple, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeTuple}; use thiserror::Error as ThisError; /// Type of compression in a system file. @@ -288,9 +289,9 @@ struct RawFormatDisplayMeaning(RawFormat); impl Display for RawFormatDisplayMeaning { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { - let type_ = format_name(self.0 .0 >> 16); - let w = (self.0 .0 >> 8) & 0xff; - let d = self.0 .0 & 0xff; + let type_ = format_name(self.0.0 >> 16); + let w = (self.0.0 >> 8) & 0xff; + let d = self.0.0 & 0xff; write!(f, "{type_}{w}.{d}") } } @@ -396,7 +397,7 @@ impl RawMissingValues { return Err(Error::new( Some(offsets), ErrorDetails::BadMissingValueCode(code), - )) + )); } }; diff --git a/rust/pspp/src/sys/sack.rs b/rust/pspp/src/sys/sack.rs index 348fda6bf5..d2ccfccc36 100644 --- a/rust/pspp/src/sys/sack.rs +++ b/rust/pspp/src/sys/sack.rs @@ -18,7 +18,7 @@ use binrw::Endian; use num::{Bounded, Zero}; use ordered_float::OrderedFloat; use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, error::Error as StdError, fmt::{Display, Formatter, Result as FmtResult}, iter::repeat_n, diff --git a/rust/pspp/src/sys/tests.rs b/rust/pspp/src/sys/tests.rs index 64750fed06..857e12ce8e 100644 --- a/rust/pspp/src/sys/tests.rs +++ b/rust/pspp/src/sys/tests.rs @@ -31,14 +31,14 @@ use crate::{ dictionary::Dictionary, identifier::Identifier, output::{ - pivot::{tests::assert_lines_eq, Axis3, Dimension, Group, PivotTable, Value}, Details, Item, Text, + pivot::{Axis3, Dimension, Group, PivotTable, Value, tests::assert_lines_eq}, }, sys::{ + WriteOptions, cooked::ReadOptions, - raw::{self, records::Compression, ErrorDetails}, + raw::{self, ErrorDetails, records::Compression}, sack::sack, - WriteOptions, }, variable::{VarWidth, Variable}, }; @@ -567,7 +567,10 @@ fn encrypted_file_without_password() { .open_file("src/crypto/testdata/test-encrypted.sav") .unwrap_err(); assert!(matches!( - error.downcast::().unwrap().details, + error + .downcast::>() + .unwrap() + .details, ErrorDetails::Encrypted )); } @@ -672,13 +675,25 @@ fn write_string(compression: Option, compression_string: &str) { .write_writer(&dictionary, Cursor::new(Vec::new())) .unwrap(); for case in [ - ["1", "1", "1", "xyzzyquux", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n"], - ["1", "2", "1", "8", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"], - ] { - cases - .write_case(case.into_iter().map(|s| Datum::String(s))) - .unwrap(); - } + [ + "1", + "1", + "1", + "xyzzyquux", + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", + ], + [ + "1", + "2", + "1", + "8", + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + ], + ] { + cases + .write_case(case.into_iter().map(|s| Datum::String(s))) + .unwrap(); + } let sysfile = cases.finish().unwrap().unwrap().into_inner(); let expected_filename = PathBuf::from(&format!( "src/sys/testdata/write-string-{compression_string}.expected" diff --git a/rust/pspp/src/sys/write.rs b/rust/pspp/src/sys/write.rs index 60f4b2cfce..741a9dd423 100644 --- a/rust/pspp/src/sys/write.rs +++ b/rust/pspp/src/sys/write.rs @@ -39,15 +39,15 @@ use crate::{ identifier::Identifier, output::spv::Zeros, sys::{ + ProductVersion, encoding::codepage_from_encoding, raw::{ + Magic, records::{ Compression, FloatInfoRecord, RawFormat, RawHeader, RawIntegerInfoRecord, RawVariableRecord, RawZHeader, RawZTrailer, ZBlock, }, - Magic, }, - ProductVersion, }, variable::{Alignment, Attributes, Measure, ValueLabels, VarWidth}, }; @@ -1232,14 +1232,14 @@ mod tests { }, identifier::Identifier, sys::{ + ReadOptions, WriteOptions, raw::{ + Decoder, VarTypes, records::{ DocumentRecord, Extension, RawHeader, RawVariableRecord, VariableRecord, }, - Decoder, VarTypes, }, write::DictionaryWriter, - ReadOptions, WriteOptions, }, variable::{Alignment, Attributes, Measure, MissingValueRange, VarWidth, Variable}, }; @@ -1694,10 +1694,12 @@ mod tests { .unwrap() .dictionary; - assert!(actual - .variable_sets() - .iter() - .eq(expected.variable_sets().iter()),); + assert!( + actual + .variable_sets() + .iter() + .eq(expected.variable_sets().iter()), + ); } /// Test writing multiple response sets. diff --git a/rust/pspp/src/variable.rs b/rust/pspp/src/variable.rs index 3b4f72741e..1ebad2cbc3 100644 --- a/rust/pspp/src/variable.rs +++ b/rust/pspp/src/variable.rs @@ -29,7 +29,7 @@ use encoding_rs::{Encoding, UTF_8}; use hashbrown::HashMap; use indexmap::Equivalent; use num::integer::div_ceil; -use serde::{ser::SerializeSeq, Serialize}; +use serde::{Serialize, ser::SerializeSeq}; use thiserror::Error as ThisError; use unicase::UniCase;