"memchr",
]
+[[package]]
+name = "allocator-api2"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
+
[[package]]
name = "android-tzdata"
version = "0.1.1"
"miniz_oxide",
]
+[[package]]
+name = "foldhash"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
+
[[package]]
name = "form_urlencoded"
version = "1.2.1"
[[package]]
name = "hashbrown"
-version = "0.15.3"
+version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
+checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
+dependencies = [
+ "allocator-api2",
+ "equivalent",
+ "foldhash",
+ "serde",
+]
[[package]]
name = "heck"
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
dependencies = [
"equivalent",
- "hashbrown 0.15.3",
+ "hashbrown 0.15.5",
"serde",
]
"enum-map",
"flagset",
"flate2",
+ "hashbrown 0.15.5",
"hexplay",
"indexmap",
"itertools",
#[repr(transparent)]
pub struct ByteStr(pub [u8]);
+impl PartialEq<ByteString> for &ByteStr {
+ fn eq(&self, other: &ByteString) -> bool {
+ self.raw_string_bytes() == other.raw_string_bytes()
+ }
+}
+
impl ByteStr {
pub fn new(s: &[u8]) -> &ByteStr {
// SAFETY: ByteStr is just a wrapper of [u8],
}
}
+ pub fn as_raw(&self) -> Datum<&ByteStr> {
+ self.as_ref().map_string(|s| s.as_ref())
+ }
+
pub fn as_encoded(&self, encoding: &'static Encoding) -> Datum<WithEncoding<&ByteStr>> {
self.as_ref().map_string(|s| s.as_encoded(encoding))
}
//! Variables.
use std::{
- collections::{BTreeMap, HashMap},
+ collections::BTreeMap,
fmt::{Debug, Display},
hash::{DefaultHasher, Hash, Hasher},
ops::{Deref, Not},
};
use encoding_rs::{Encoding, UTF_8};
+use hashbrown::HashMap;
+use indexmap::Equivalent;
use num::integer::div_ceil;
use serde::{ser::SerializeSeq, Serialize};
use thiserror::Error as ThisError;
use unicase::UniCase;
use crate::{
- data::{ByteString, Datum, Encoded, EncodedString, ResizeError, WithEncoding},
+ data::{
+ ByteStr, ByteString, Datum, Encoded, EncodedString, RawString, ResizeError, WithEncoding,
+ },
format::{DisplayPlain, Format},
identifier::{HasIdentifier, Identifier},
};
#[derive(Clone, Default, PartialEq, Eq)]
pub struct ValueLabels(pub HashMap<Datum<ByteString>, String>);
+impl<'a> Equivalent<Datum<ByteString>> for Datum<&'a ByteStr> {
+ fn equivalent(&self, key: &Datum<ByteString>) -> bool {
+ self == key
+ }
+}
+
impl ValueLabels {
pub fn new() -> Self {
Self::default()
self.0.is_empty()
}
- pub fn get(&self, value: &Datum<ByteString>) -> Option<&str> {
- self.0.get(value).map(|s| s.as_str())
+ pub fn get<T>(&self, value: &Datum<T>) -> Option<&str>
+ where
+ T: RawString,
+ {
+ self.0.get(&value.as_raw()).map(|s| s.as_str())
}
pub fn insert(&mut self, value: Datum<ByteString>, label: impl Into<String>) -> Option<String> {