Skip to content

Commit 6c5fdb4

Browse files
committed
Fixed return type of load_mem; clippy happy
1 parent c6bb313 commit 6c5fdb4

File tree

13 files changed

+58
-55
lines changed

13 files changed

+58
-55
lines changed

CHANGELOG.md

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

3-
## [0.6.2] - 2024-07-19
3+
## [0.6.2] - 2025-02-07
4+
5+
### Improved
6+
7+
* Added missing implementation of `TypeHash`, `ReprHash`, `MaxSizeOf`,
8+
`SerializeInner`, `DeserializeInner` for `Range`, `RangeFrom`, `RangeFull`,
9+
`RangeInclusive`, `RangeTo`, `RangeToInclusive`, `Bound`, `ControlFlow`.
410

511
### Fixed
612

7-
* Added missing implementation of `TypeHash`, `ReprHash`, `MaxSizeOf`,
8-
`SerializeInner`, `DeserializeInner` for:
9-
`Range`, `RangeFrom`, `RangeFull`, `RangeInclusive`, `RangeTo`,
10-
`RangeToInclusive`, `Bound`, `ControlFlow`.
13+
* The return type of `Deserialize::load_full` is how an `anyhow::Result`,
14+
analogously to the other `load` functions.
1115

1216
## [0.6.1] - 2024-06-03
1317

README.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,44 +60,45 @@ These are the main limitations you should be aware of before choosing to use
6060
tree.
6161

6262
- While we provide procedural macros that implement serialization and
63-
deserialization, they require that your type is written and used in a specific
64-
way; in particular, the fields you want to ε-copy must be type parameters
65-
implementing [`DeserializeInner`], to which a [deserialized type] is associated.
66-
For example, we provide implementations for `Vec<T>`/`Box<[T]>`, where `T` is
67-
zero-copy, or `String`/`Box<str>`, which have associated deserialized type
68-
`&[T]` or `&str`, respectively. Vectors and boxed slices of types that are not
69-
zero-copy will be deserialized recursively in memory instead.
63+
deserialization, they require that your type is written and used in a specific
64+
way; in particular, the fields you want to ε-copy must be type parameters
65+
implementing [`DeserializeInner`], to which a [deserialized type] is
66+
associated. For example, we provide implementations for `Vec<T>`/`Box<[T]>`,
67+
where `T` is zero-copy, or `String`/`Box<str>`, which have associated
68+
deserialized type `&[T]` or `&str`, respectively. Vectors and boxed slices of
69+
types that are not zero-copy will be deserialized recursively in memory
70+
instead.
7071

7172
- After deserialization of a type `T`, you will obtain an associated
72-
deserialized type [`DeserType<'_,T>`], which will usually reference the
73-
underlying serialized support (e.g., a memory-mapped region); hence the need for
74-
a lifetime. If you need to store the deserialized structure in a field of a new
75-
structure you will need to couple permanently the deserialized structure with
76-
its serialized support, which is obtained by putting it in a [`MemCase`] using
77-
the convenience methods [`Deserialize::load_mem`], [`Deserialize::load_mmap`],
78-
and [`Deserialize::mmap`]. A [`MemCase`] will deref to its contained type, so it
79-
can be used transparently as long as fields and methods are concerned, but if
80-
your original type is `T` the field of the new structure will have to be of type
81-
`MemCase<DeserType<'static, T>>`, not `T`.
73+
deserialized type [`DeserType<'_,T>`], which will usually reference the
74+
underlying serialized support (e.g., a memory-mapped region); hence the need for
75+
a lifetime. If you need to store the deserialized structure in a field of a new
76+
structure you will need to couple permanently the deserialized structure with
77+
its serialized support, which is obtained by putting it in a [`MemCase`] using
78+
the convenience methods [`Deserialize::load_mem`], [`Deserialize::load_mmap`],
79+
and [`Deserialize::mmap`]. A [`MemCase`] will deref to its contained type, so it
80+
can be used transparently as long as fields and methods are concerned, but if
81+
your original type is `T` the field of the new structure will have to be of type
82+
`MemCase<DeserType<'static, T>>`, not `T`.
8283

8384
## Pros
8485

8586
- Almost instant deserialization with minimal allocation provided that you
86-
designed your type following the ε-serde guidelines or that you use standard
87-
types.
87+
designed your type following the ε-serde guidelines or that you use standard
88+
types.
8889

8990
- The structure you get by deserialization is the same structure you serialized,
90-
except that type parameters will be replaced by their associated deserialization
91-
type (e.g., vectors will become references to slices). This is not the
92-
case with [rkiv], which requires you to reimplement all methods on the
93-
deserialized type.
91+
except that type parameters will be replaced by their associated deserialization
92+
type (e.g., vectors will become references to slices). This is not the
93+
case with [rkiv], which requires you to reimplement all methods on the
94+
deserialized type.
9495

9596
- The structure you get by deserialization has exactly the same performance as
96-
the structure you serialized. This is not the case with [zerovec] or [rkiv].
97+
the structure you serialized. This is not the case with [zerovec] or [rkiv].
9798

9899
- You can deserialize from read-only supports, as all dynamic information
99-
generated at deserialization time is stored in newly allocated memory. This is
100-
not the case with [Abomonation].
100+
generated at deserialization time is stored in newly allocated memory. This is
101+
not the case with [Abomonation].
101102

102103
## Example: Zero copy of standard types
103104

@@ -298,20 +299,20 @@ s.store(&file);
298299
let b = std::fs::read(&file)?;
299300

300301
// The type of t will be inferred--it is shown here only for clarity
301-
let t: DeserType<'_, MyStruct<Vec<isize>>> =
302+
let t: MyStruct<&[isize]> =
302303
<MyStruct<Vec<isize>>>::deserialize_eps(b.as_ref())?;
303304

304305
assert_eq!(s.id, t.id);
305306
assert_eq!(s.data, Vec::from(t.data));
306307

307308
// This is a traditional deserialization instead
308309
let t: MyStruct<Vec<isize>> =
309-
<MyStruct::<Vec<isize>>>::load_full(&file)?;
310+
<MyStruct<Vec<isize>>>::load_full(&file)?;
310311
assert_eq!(s, t);
311312

312313
// In this case we map the data structure into memory
313-
let u: MemCase<DeserType<'static, MyStruct<Vec<isize>>>> =
314-
<MyStruct::<Vec<isize>>>::mmap(&file, Flags::empty())?;
314+
let u: MemCase<MyStruct<&[isize]>> =
315+
<MyStruct<Vec<isize>>>::mmap(&file, Flags::empty())?;
315316
assert_eq!(s.id, u.id);
316317
assert_eq!(s.data, u.data.as_ref());
317318
# Ok(())
@@ -486,7 +487,7 @@ Every type serializable with ε-serde has two features that are in principle
486487
orthogonal, but that in practice often condition one another:
487488

488489
- the type has an *associated deserialization type*, which is the type you
489-
obtain upon deserialization;
490+
obtain upon deserialization;
490491
- the type can be either [`ZeroCopy`] or [`DeepCopy`]; it can also be neither.
491492

492493
There is no constraint on the associated deserialization type: it can be
@@ -513,11 +514,11 @@ types are always fully deserialized*. There are two reasons behind this
513514
non-orthogonal choice:
514515

515516
- primitive types occupy so little space that deserializing them as a reference
516-
is not efficient;
517+
is not efficient;
517518
- if a type parameter `T` is a primitive type, writing generic code for
518-
`AsRef<T>` is really not nice;
519+
`AsRef<T>` is really not nice;
519520
- deserializing primitive types to a reference would require further padding to
520-
align them.
521+
align them.
521522

522523
Since this is true only of primitive types, when deserializing a 1-tuple
523524
containing a primitive type one obtains a reference (and indeed this workaround

epserde/examples/array.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use epserde::prelude::*;
99
use maligned::A16;
1010

1111
/// Example of zero-copy deserialization of an array.
12-
1312
fn main() {
1413
// Create a vector to serialize
1514

epserde/examples/onetuple_zero_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
println!();
3232

3333
// Do an ε-copy deserialization (which will be zero-copy deserialization)
34-
let eps = <(usize,)>::deserialize_eps(&cursor.as_bytes()).unwrap();
34+
let eps = <(usize,)>::deserialize_eps(cursor.as_bytes()).unwrap();
3535
println!(
3636
"ε-copy deserialization type: {}",
3737
std::any::type_name::<<(usize,) as DeserializeInner>::DeserType<'_>>(),

epserde/src/deser/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ pub trait Deserialize: TypeHash + ReprHash + DeserializeInner {
5353
/// ε-copy deserialize a structure of this type from the given backend.
5454
fn deserialize_eps(backend: &'_ [u8]) -> Result<Self::DeserType<'_>>;
5555

56-
/// Commodity method to fully deserialize from a file.
57-
fn load_full(path: impl AsRef<Path>) -> Result<Self> {
56+
/// Convenience method to fully deserialize from a file.
57+
fn load_full(path: impl AsRef<Path>) -> anyhow::Result<Self> {
5858
let file = std::fs::File::open(path).map_err(Error::FileOpenError)?;
5959
let mut buf_reader = BufReader::new(file);
60-
Self::deserialize_full(&mut buf_reader)
60+
Self::deserialize_full(&mut buf_reader).map_err(|e| e.into())
6161
}
6262

6363
/// Load a file into heap-allocated memory and ε-deserialize a data structure from it,

epserde/src/deser/reader_with_pos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ impl<'a, F: ReadNoStd> ReaderWithPos<'a, F> {
2828
}
2929
}
3030

31-
impl<'a, F: ReadNoStd> ReadNoStd for ReaderWithPos<'a, F> {
31+
impl<F: ReadNoStd> ReadNoStd for ReaderWithPos<'_, F> {
3232
fn read_exact(&mut self, buf: &mut [u8]) -> deser::Result<()> {
3333
self.backend.read_exact(buf)?;
3434
self.pos += buf.len();
3535
Ok(())
3636
}
3737
}
3838

39-
impl<'a, F: ReadNoStd> ReadWithPos for ReaderWithPos<'a, F> {
39+
impl<F: ReadNoStd> ReadWithPos for ReaderWithPos<'_, F> {
4040
fn pos(&self) -> usize {
4141
self.pos
4242
}

epserde/src/deser/slice_with_pos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a> SliceWithPos<'a> {
3131
}
3232
}
3333

34-
impl<'a> ReadNoStd for SliceWithPos<'a> {
34+
impl ReadNoStd for SliceWithPos<'_> {
3535
fn read_exact(&mut self, buf: &mut [u8]) -> deser::Result<()> {
3636
let len = buf.len();
3737
if len > self.data.len() {
@@ -44,7 +44,7 @@ impl<'a> ReadNoStd for SliceWithPos<'a> {
4444
}
4545
}
4646

47-
impl<'a> ReadWithPos for SliceWithPos<'a> {
47+
impl ReadWithPos for SliceWithPos<'_> {
4848
fn pos(&self) -> usize {
4949
self.pos
5050
}

epserde/src/impls/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl<T: ZeroCopy + DeserializeInner + 'static, const N: usize> DeserializeHelper
9999
Ok(res.assume_init())
100100
}
101101
}
102-
#[inline(always)]
103102

103+
#[inline(always)]
104104
fn _deserialize_eps_inner_impl<'a>(
105105
backend: &mut SliceWithPos<'a>,
106106
) -> deser::Result<<Self as DeserializeInner>::DeserType<'a>> {

epserde/src/impls/stdlib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<Idx: DeserializeInner> DeserializeInner for core::ops::RangeInclusive<Idx>
153153
let end = Idx::_deserialize_eps_inner(backend)?;
154154
let exhausted = bool::_deserialize_full_inner(backend)?;
155155
assert!(!exhausted, "cannot deserialize an exhausted range");
156-
return Ok(start..=end);
156+
Ok(start..=end)
157157
}
158158
}
159159

epserde/src/ser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub trait Serialize: TypeHash + ReprHash {
6363
/// Serialize the type using the given [`WriteWithNames`].
6464
fn serialize_on_field_write(&self, backend: &mut impl WriteWithNames) -> Result<()>;
6565

66-
/// Commodity method to serialize to a file.
66+
/// Convenience method to serialize to a file.
6767
fn store(&self, path: impl AsRef<Path>) -> Result<()> {
6868
let file = std::fs::File::create(path).map_err(Error::FileOpenError)?;
6969
let mut buf_writer = BufWriter::new(file);

0 commit comments

Comments
 (0)