format::DisplayPlain,
};
-pub trait RawStringTrait: Debug + PartialEq + Eq + PartialOrd + Ord + Hash {
+pub trait RawString: Debug + PartialEq + Eq + PartialOrd + Ord + Hash {
fn raw_string_bytes(&self) -> &[u8];
/// Compares this string and `other` for equality, ignoring trailing ASCII
/// known).
fn eq_ignore_trailing_spaces<R>(&self, other: &R) -> bool
where
- R: RawStringTrait,
+ R: RawString,
{
self.raw_string_bytes()
.iter()
}
}
-pub trait MutRawString: RawStringTrait {
+pub trait MutRawString: RawString {
fn resize(&mut self, new_len: usize) -> Result<(), ResizeError>;
fn trim_end(&mut self);
}
-impl RawStringTrait for &'_ str {
+impl RawString for &'_ str {
fn raw_string_bytes(&self) -> &[u8] {
self.as_bytes()
}
}
-impl RawStringTrait for String {
+impl RawString for String {
fn raw_string_bytes(&self) -> &[u8] {
self.as_bytes()
}
}
-impl RawStringTrait for &'_ String {
+impl RawString for &'_ String {
fn raw_string_bytes(&self) -> &[u8] {
self.as_bytes()
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ByteStr<'a>(pub &'a [u8]);
-impl RawStringTrait for ByteStr<'_> {
+impl RawString for ByteStr<'_> {
fn raw_string_bytes(&self) -> &[u8] {
self.0
}
}
}
-impl RawStringTrait for ByteCow<'_> {
+impl RawString for ByteCow<'_> {
fn raw_string_bytes(&self) -> &[u8] {
&self.0
}
}
}
-impl RawStringTrait for ByteString {
+impl RawString for ByteString {
fn raw_string_bytes(&self) -> &[u8] {
self.0.as_slice()
}
}
mod encoded;
-pub use encoded::{Encoded, EncodedStringTrait, WithEncoding};
+pub use encoded::{Encoded, EncodedString, WithEncoding};
/// A [Datum] that owns its string data (if any).
pub type OwnedDatum = Datum<WithEncoding<ByteString>>;
impl<T> Datum<T>
where
- T: EncodedStringTrait,
+ T: EncodedString,
{
pub fn as_borrowed(&self) -> Datum<WithEncoding<ByteStr<'_>>> {
match self {
impl<T> Datum<T>
where
- T: RawStringTrait,
+ T: RawString,
{
/// Returns true if this datum can be resized to the given `width` without
/// loss, which is true only if this datum and `width` are both string or
/// comparison.
pub fn eq_ignore_trailing_spaces<R>(&self, other: &Datum<R>) -> bool
where
- R: RawStringTrait,
+ R: RawString,
{
match (self, other) {
(Self::String(a), Datum::String(b)) => a.eq_ignore_trailing_spaces(b),
impl<B> Datum<B>
where
- B: EncodedStringTrait,
+ B: EncodedString,
{
pub fn quoted<'a>(&'a self) -> QuotedDatum<'a, B> {
QuotedDatum(self)
use encoding_rs::{Encoding, UTF_8};
use serde::Serialize;
-use crate::data::{
- ByteCow, ByteStr, ByteString, MutRawString, Quoted, RawStringTrait, ResizeError,
-};
+use crate::data::{ByteCow, ByteStr, ByteString, MutRawString, Quoted, RawString, ResizeError};
pub trait Encoded {
fn encoding(&self) -> &'static Encoding;
impl<T> Serialize for WithEncoding<T>
where
- WithEncoding<T>: EncodedStringTrait,
+ WithEncoding<T>: EncodedString,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
}
}
-pub trait EncodedStringTrait: Encoded + RawStringTrait + Display + Debug {
+pub trait EncodedString: Encoded + RawString + Display + Debug {
fn as_str(&self) -> Cow<'_, str>;
fn into_string(self) -> String
where
}
}
-impl<'a> EncodedStringTrait for &'a str {
+impl<'a> EncodedString for &'a str {
fn as_str(&self) -> Cow<'_, str> {
Cow::from(*self)
}
}
}
-impl EncodedStringTrait for String {
+impl EncodedString for String {
fn as_str(&self) -> Cow<'_, str> {
Cow::from(String::as_str(&self))
}
}
}
-impl EncodedStringTrait for &'_ String {
+impl EncodedString for &'_ String {
fn as_str(&self) -> Cow<'_, str> {
Cow::from(String::as_str(&self))
}
}
}
-impl<T> RawStringTrait for WithEncoding<T>
+impl<T> RawString for WithEncoding<T>
where
- T: RawStringTrait,
+ T: RawString,
{
fn raw_string_bytes(&self) -> &[u8] {
self.inner.raw_string_bytes()
}
}
-impl<T> EncodedStringTrait for WithEncoding<T>
+impl<T> EncodedString for WithEncoding<T>
where
- T: RawStringTrait,
+ T: RawString,
{
/// Returns this string recoded in UTF-8. Invalid characters will be
/// replaced by [REPLACEMENT_CHARACTER].
impl<T> Display for WithEncoding<T>
where
- T: RawStringTrait,
+ T: RawString,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.as_str())
use unicase::UniCase;
use crate::{
- data::{ByteString, Datum, EncodedStringTrait, ResizeError, WithEncoding},
+ data::{ByteString, Datum, EncodedString, ResizeError, WithEncoding},
format::{DisplayPlain, Format},
identifier::{ByIdentifier, HasIdentifier, Identifier},
output::pivot::{
pub fn contains<S>(&self, value: &Datum<S>) -> bool
where
- S: EncodedStringTrait,
+ S: EncodedString,
{
if self
.values
use crate::{
calendar::{calendar_offset_to_gregorian, day_of_year, month_name, short_month_name},
- data::{ByteStr, Datum, EncodedStringTrait, QuotedDatum, WithEncoding},
+ data::{ByteStr, Datum, EncodedString, QuotedDatum, WithEncoding},
endian::{endian_to_smallvec, ToBytes},
format::{Category, DateTemplate, Decimal, Format, NumberStyle, Settings, TemplateItem, Type},
settings::{EndianSettings, Settings as PsppSettings},
}
}
-/*
-impl<R> EncodedDatum<EncodedString<R>>
-where
- R: Borrow<BorrowedRawString>,
-{
- /// Returns an object that implements [Display] for printing this
- /// [EncodedDatum] as `format`.
- ///
- /// [Display]: std::fmt::Display
- pub fn display(&self, format: Format) -> DisplayDatum {
- DisplayDatum::new(format, self.borrowed())
- }
-
- pub fn display_plain(&self) -> QuotedEncodedDatum<'_> {
- self.quoted()
- }
-}*/
-
impl<'a, D> Datum<D>
where
- D: EncodedStringTrait,
+ D: EncodedString,
{
/// Returns an object that implements [Display] for printing this
/// [EncodedDatum] as `format`.
impl<'a, 'b, B> Display for DisplayDatum<'b, B>
where
- B: EncodedStringTrait,
+ B: EncodedString,
{
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let number = match &self.datum {
impl<'b, B> DisplayDatum<'b, B>
where
- B: EncodedStringTrait,
+ B: EncodedString,
{
pub fn new(format: Format, datum: Datum<B>) -> Self {
let settings = PsppSettings::global();
use crate::{
calendar::{calendar_gregorian_to_offset, DateError},
- data::{ByteString, Datum, EncodedStringTrait, OwnedDatum, RawStringTrait, WithEncoding},
+ data::{ByteString, Datum, EncodedString, OwnedDatum, RawString, WithEncoding},
endian::{Endian, Parse},
format::{DateTemplate, Decimals, Settings, TemplateItem, Type},
settings::{EndianSettings, Settings as PsppSettings},
/// input into UTF-8, but this will screw up parsing of binary formats,
/// because recoding bytes from (e.g.) windows-1252 into UTF-8, and then
/// interpreting them as a binary number yields nonsense.
- pub fn parse(&self, input: impl EncodedStringTrait) -> Result<OwnedDatum, ParseError> {
+ pub fn parse(&self, input: impl EncodedString) -> Result<OwnedDatum, ParseError> {
if input.is_empty() {
return Ok(self
.type_
use crate::{
calendar::{days_in_month, is_leap_year},
- data::{ByteStr, Datum, EncodedStringTrait, OwnedDatum, RawStringTrait},
+ data::{ByteStr, Datum, EncodedString, OwnedDatum, RawString},
endian::Endian,
format::{
parse::{ParseError, ParseErrorKind, Sign},
use tlo::parse_tlo;
use crate::{
- data::{ByteString, Datum, EncodedStringTrait, RawStringTrait},
+ data::{ByteString, Datum, EncodedString, RawString},
dictionary::{VarType, Variable},
format::{Decimal, Format, Settings as FormatSettings, Type, UncheckedFormat},
settings::{Settings, Show},
}
pub fn new_datum<B>(value: &Datum<B>) -> Self
where
- B: EncodedStringTrait,
+ B: EncodedString,
{
match value {
Datum::Number(number) => Self::new_number(*number),
use crate::{
calendar::date_time_to_pspp,
crypto::EncryptedFile,
- data::{ByteString, Case, Datum, MutRawString, RawStringTrait},
+ data::{ByteString, Case, Datum, MutRawString, RawString},
dictionary::{
DictIndexMultipleResponseSet, DictIndexVariableSet, Dictionary, InvalidRole, MissingValues,
MissingValuesError, MultipleResponseType, VarWidth, Variable,
use crate::{
crypto::EncryptedFile,
- data::{BorrowedDatum, ByteString, Datum, OwnedDatum},
+ data::{BorrowedDatum, ByteString, Datum},
dictionary::{Dictionary, VarWidth, Variable},
endian::Endian,
identifier::Identifier,
use smallvec::SmallVec;
use crate::{
- data::{Datum, RawStringTrait},
+ data::{Datum, RawString},
dictionary::{
Alignment, Attributes, CategoryLabels, Dictionary, Measure, MultipleResponseType,
ValueLabels, VarWidth,
impl<B> BinWrite for Datum<B>
where
- B: RawStringTrait,
+ B: RawString,
{
type Args<'a> = ();
case: impl Iterator<Item = Datum<B>>,
) -> Result<(), BinError>
where
- B: RawStringTrait,
+ B: RawString,
{
for (var, datum) in zip_eq(self.case_vars, case) {
match var {
case: impl Iterator<Item = Datum<B>>,
) -> Result<(), BinError>
where
- B: RawStringTrait,
+ B: RawString,
{
for (var, datum) in zip_eq(self.case_vars, case) {
match var {
case: impl IntoIterator<Item = Datum<B>>,
) -> Result<(), BinError>
where
- B: RawStringTrait,
+ B: RawString,
{
match self.inner.as_mut().unwrap() {
Either::Left(inner) => {