Skip to content

Commit d6da76c

Browse files
committed
Fixed type hash of strings
1 parent 8b89a09 commit d6da76c

File tree

8 files changed

+21
-28
lines changed

8 files changed

+21
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [0.10.1] - 2025-09-25
4+
5+
### Fixed
6+
7+
* Fixed type hash of strings.
8+
39
## [0.10.0] - 2025-09-25
410

511
### New

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ members = [
77
]
88

99
[workspace.dependencies]
10-
epserde = {path="./epserde", version="0.10.0"}
10+
epserde = {path="./epserde", version="0.10.1"}
1111
epserde-derive = {path="./epserde-derive", version="0.10.0"}

epserde/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [
66
"Sebastiano Vigna <sebastiano.vigna@unimi.it>",
77
]
88
description = "ε-serde is an ε-copy (i.e., almost zero-copy) serialization/deserialization framework"
9-
version = "0.10.0"
9+
version = "0.10.1"
1010
edition = "2024"
1111
repository = "https://github.com/vigna/epserde-rs/"
1212
license = "Apache-2.0 OR LGPL-2.1-or-later"

epserde/src/impls/string.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ use ser::*;
2323
#[cfg(not(feature = "std"))]
2424
use alloc::boxed::Box;
2525

26-
impl TypeHash for str {
27-
fn type_hash(hasher: &mut impl core::hash::Hasher) {
28-
"str".hash(hasher);
29-
}
30-
}
31-
32-
impl AlignHash for str {
33-
fn align_hash(_hasher: &mut impl core::hash::Hasher, _offset_of: &mut usize) {}
34-
}
35-
3626
unsafe impl CopyType for String {
3727
type Copy = Deep;
3828
}
@@ -42,7 +32,7 @@ use alloc::string::String;
4232

4333
impl TypeHash for String {
4434
fn type_hash(hasher: &mut impl core::hash::Hasher) {
45-
"String".hash(hasher);
35+
<Box<str>>::type_hash(hasher);
4636
}
4737
}
4838

epserde/src/ser/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pub trait WriteWithPos: WriteNoStd {
6161
fn pos(&self) -> usize;
6262
}
6363

64-
/// A wrapper for a [`WriteNoStd`] that implements [`WriteWithPos`]
65-
/// by keeping track of the current position.
64+
/// A wrapper for a [`WriteNoStd`] that implements [`WriteWithPos`] by keeping
65+
/// track of the current position.
6666
#[derive(Debug)]
6767
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg, mem_dbg::MemSize))]
6868
pub struct WriterWithPos<'a, F: WriteNoStd> {

epserde/src/ser/write_with_names.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@ use alloc::{
2020
vec::Vec,
2121
};
2222

23-
/// Trait extending [`WriteWithPos`] with methods providing
24-
/// alignment, serialization of named data, and writing of byte slices
25-
/// of zero-copy types.
23+
/// Trait extending [`WriteWithPos`] with methods providing alignment,
24+
/// serialization of named data, and writing of byte slices of zero-copy types.
2625
///
27-
/// The purpose of this trait is that of interposing between [`SerInner`]
28-
/// and the underlying [`WriteWithPos`] a layer in which serialization operations
26+
/// The purpose of this trait is that of interposing between [`SerInner`] and
27+
/// the underlying [`WriteWithPos`] a layer in which serialization operations
2928
/// can be easily intercepted and recorded. In particular, serialization methods
3029
/// must use the methods of this trait if they want to record the schema of the
3130
/// serialized data; this is true (maybe counterintuitively) even of ancillary
32-
/// data such as tags and slice lengths: see [`helpers`] or the
33-
/// [implementation of `Option`](impls::prim) for examples.
34-
/// All methods have a default
31+
/// data such as tags and slice lengths: see [`helpers`] or the [implementation
32+
/// of `Option`](impls::prim) for examples. All methods have a default
3533
/// implementation that must be replicated in other implementations.
3634
///
3735
/// There are two implementations of [`WriteWithNames`]: [`WriterWithPos`],
38-
/// which uses the default implementation, and [`SchemaWriter`],
39-
/// which additionally records a [`Schema`] of the serialized data.
36+
/// which uses the default implementation, and [`SchemaWriter`], which
37+
/// additionally records a [`Schema`] of the serialized data.
4038
pub trait WriteWithNames: WriteWithPos + Sized {
4139
/// Add some zero padding so that `self.pos() % V:max_size_of() == 0.`
4240
///

epserde/tests/test_regression.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ fn test_option() {
6868

6969
#[test]
7070
fn test_string_types() {
71-
assert_eq!(get_type_hash::<String>(), 0xe4297f5be0f5dd50);
71+
assert_eq!(get_type_hash::<String>(), 0x19aa1d67f7ad7a3e);
7272
assert_eq!(get_align_hash::<String>(), 0xd1fba762150c532c);
7373
assert_eq!(get_type_hash::<Box<str>>(), 0x19aa1d67f7ad7a3e);
7474
assert_eq!(get_align_hash::<Box<str>>(), 0xd1fba762150c532c);
75-
// TODO assert_eq!(get_type_hash::<str>(), 0x393e833de113cd8c);
7675
}
7776

7877
#[test]

0 commit comments

Comments
 (0)