From: Ben Pfaff Date: Sat, 2 Aug 2025 16:49:06 +0000 (-0700) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b78748d23bbfefc0941f42732db24225ca4ca134;p=pspp cleanup --- diff --git a/rust/pspp/src/endian.rs b/rust/pspp/src/endian.rs index b52d66d84e..906b23ba61 100644 --- a/rust/pspp/src/endian.rs +++ b/rust/pspp/src/endian.rs @@ -1,3 +1,5 @@ +//! Converting big- and little-endian `[u8]` arrays to and from primitive types. + // PSPP - a program for statistical analysis. // Copyright (C) 2025 Free Software Foundation, Inc. // @@ -16,6 +18,7 @@ use binrw::Endian; +/// Converts a primitive type into a big- or little-endian `[u8]` array. pub trait ToBytes { fn to_bytes(self, value: T) -> [u8; N]; } @@ -73,13 +76,12 @@ impl ToBytes for Endian { } } -/// Parses an `N`-byte array in one of the supported formats into native format -/// as type `T`. -pub trait Parse { +/// Parses a `[u8]` array as a big- or little-endian primitive type. +pub trait FromBytes { /// Given 'bytes', returns `T`. fn parse(self, bytes: [u8; N]) -> T; } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 8]) -> u64 { match self { Endian::Big => u64::from_be_bytes(bytes), @@ -87,7 +89,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 4]) -> u32 { match self { Endian::Big => u32::from_be_bytes(bytes), @@ -95,7 +97,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 2]) -> u16 { match self { Endian::Big => u16::from_be_bytes(bytes), @@ -103,7 +105,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 1]) -> u8 { match self { Endian::Big => u8::from_be_bytes(bytes), @@ -111,7 +113,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 8]) -> i64 { match self { Endian::Big => i64::from_be_bytes(bytes), @@ -119,7 +121,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 4]) -> i32 { match self { Endian::Big => i32::from_be_bytes(bytes), @@ -127,7 +129,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 2]) -> i16 { match self { Endian::Big => i16::from_be_bytes(bytes), @@ -135,7 +137,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 1]) -> i8 { match self { Endian::Big => i8::from_be_bytes(bytes), @@ -143,7 +145,7 @@ impl Parse for Endian { } } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 8]) -> f64 { match self { Endian::Big => f64::from_be_bytes(bytes), @@ -151,13 +153,13 @@ impl Parse for Endian { } } } -impl Parse, 8> for Endian { +impl FromBytes, 8> for Endian { fn parse(self, bytes: [u8; 8]) -> Option { let number: f64 = self.parse(bytes); (number != -f64::MAX).then_some(number) } } -impl Parse for Endian { +impl FromBytes for Endian { fn parse(self, bytes: [u8; 4]) -> f32 { match self { Endian::Big => f32::from_be_bytes(bytes), @@ -165,7 +167,7 @@ impl Parse for Endian { } } } -impl Parse, 4> for Endian { +impl FromBytes, 4> for Endian { fn parse(self, bytes: [u8; 4]) -> Option { let number: f32 = self.parse(bytes); (number != -f32::MAX).then_some(number) diff --git a/rust/pspp/src/format/parse.rs b/rust/pspp/src/format/parse.rs index a43e59bb54..3e5d257a6e 100644 --- a/rust/pspp/src/format/parse.rs +++ b/rust/pspp/src/format/parse.rs @@ -17,7 +17,7 @@ use crate::{ calendar::{calendar_gregorian_to_offset, DateError}, data::{ByteString, Datum, EncodedString, OwnedDatum, RawString, WithEncoding}, - endian::Parse, + endian::FromBytes, format::{DateTemplate, Decimals, Settings, TemplateItem, Type}, settings::{EndianSettings, Settings as PsppSettings}, }; diff --git a/rust/pspp/src/sys/raw.rs b/rust/pspp/src/sys/raw.rs index 14410ee030..9b88153a8f 100644 --- a/rust/pspp/src/sys/raw.rs +++ b/rust/pspp/src/sys/raw.rs @@ -22,7 +22,7 @@ use crate::{ data::{ByteStr, ByteString, Datum, RawCase}, dictionary::{VarType, VarWidth}, - endian::{Parse, ToBytes}, + endian::{FromBytes, ToBytes}, identifier::{Error as IdError, Identifier}, sys::{ encoding::{default_encoding, get_encoding, Error as EncodingError}, diff --git a/rust/pspp/src/sys/raw/records.rs b/rust/pspp/src/sys/raw/records.rs index bd91fc7b3b..8753eaa2a9 100644 --- a/rust/pspp/src/sys/raw/records.rs +++ b/rust/pspp/src/sys/raw/records.rs @@ -17,7 +17,7 @@ use crate::{ Alignment, Attributes, CategoryLabels, Measure, MissingValueRange, MissingValues, MissingValuesError, VarType, VarWidth, }, - endian::{Parse}, + endian::{FromBytes}, format::{DisplayPlainF64, Format, Type}, identifier::{Error as IdError, Identifier}, sys::{