Skip to content

Commit 0dd176a

Browse files
authored
Merge pull request #169 from barafael/edition-2021
Update to edition 2021 (and clippy fixes)
2 parents bffc76c + eaa410d commit 0dd176a

File tree

10 files changed

+74
-65
lines changed

10 files changed

+74
-65
lines changed

source/postcard/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "postcard"
33
version = "1.1.0"
44
authors = ["James Munns <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66
readme = "README.md"
77
repository = "https://github.com/jamesmunns/postcard"
88
description = "A no_std + serde compatible message library for Rust"
@@ -77,7 +77,7 @@ embedded-io-04 = ["dep:embedded-io-04"]
7777
embedded-io-06 = ["dep:embedded-io-06"]
7878

7979
use-std = ["serde/std", "alloc"]
80-
heapless-cas = ["heapless", "heapless/cas"]
80+
heapless-cas = ["heapless", "dep:heapless", "heapless/cas"]
8181
alloc = ["serde/alloc", "embedded-io-04?/alloc", "embedded-io-06?/alloc"]
8282
use-defmt = ["defmt"]
8383
use-crc = ["crc", "paste"]
@@ -86,3 +86,8 @@ use-crc = ["crc", "paste"]
8686
#
8787
# NOT subject to SemVer guarantees!
8888
experimental-derive = ["postcard-derive"]
89+
crc = ["dep:crc"]
90+
defmt = ["dep:defmt"]
91+
heapless = ["dep:heapless"]
92+
paste = ["dep:paste"]
93+
postcard-derive = ["dep:postcard-derive"]

source/postcard/src/de/deserializer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'de, F: Flavor<'de>> Deserializer<'de, F> {
139139
}
140140
}
141141

142-
struct SeqAccess<'a, 'b: 'a, F: Flavor<'b>> {
142+
struct SeqAccess<'a, 'b, F: Flavor<'b>> {
143143
deserializer: &'a mut Deserializer<'b, F>,
144144
len: usize,
145145
}
@@ -169,7 +169,7 @@ impl<'a, 'b: 'a, F: Flavor<'b>> serde::de::SeqAccess<'b> for SeqAccess<'a, 'b, F
169169
}
170170
}
171171

172-
struct MapAccess<'a, 'b: 'a, F: Flavor<'b>> {
172+
struct MapAccess<'a, 'b, F: Flavor<'b>> {
173173
deserializer: &'a mut Deserializer<'b, F>,
174174
len: usize,
175175
}
@@ -201,7 +201,7 @@ impl<'a, 'b: 'a, F: Flavor<'b>> serde::de::MapAccess<'b> for MapAccess<'a, 'b, F
201201
}
202202
}
203203

204-
impl<'de, 'a, F: Flavor<'de>> de::Deserializer<'de> for &'a mut Deserializer<'de, F> {
204+
impl<'de, F: Flavor<'de>> de::Deserializer<'de> for &mut Deserializer<'de, F> {
205205
type Error = Error;
206206

207207
#[inline]
@@ -539,7 +539,7 @@ impl<'de, 'a, F: Flavor<'de>> de::Deserializer<'de> for &'a mut Deserializer<'de
539539
}
540540
}
541541

542-
impl<'de, 'a, F: Flavor<'de>> serde::de::VariantAccess<'de> for &'a mut Deserializer<'de, F> {
542+
impl<'de, F: Flavor<'de>> serde::de::VariantAccess<'de> for &mut Deserializer<'de, F> {
543543
type Error = Error;
544544

545545
#[inline]
@@ -567,7 +567,7 @@ impl<'de, 'a, F: Flavor<'de>> serde::de::VariantAccess<'de> for &'a mut Deserial
567567
}
568568
}
569569

570-
impl<'de, 'a, F: Flavor<'de>> serde::de::EnumAccess<'de> for &'a mut Deserializer<'de, F> {
570+
impl<'de, F: Flavor<'de>> serde::de::EnumAccess<'de> for &mut Deserializer<'de, F> {
571571
type Error = Error;
572572
type Variant = Self;
573573

source/postcard/src/de/flavors.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'de> Flavor<'de> for Slice<'de> {
189189
}
190190
}
191191

192-
/// Support for [std::io] or `embedded-io` traits
192+
/// Support for [`std::io`] or `embedded-io` traits
193193
#[cfg(any(
194194
feature = "embedded-io-04",
195195
feature = "embedded-io-06",
@@ -248,7 +248,7 @@ pub mod io {
248248
use super::SlidingBuffer;
249249
use crate::{Error, Result};
250250

251-
/// Wrapper over a [`embedded_io`](crate::eio::embedded_io)::[`Read`](crate::eio::Read) and a sliding buffer to implement the [Flavor] trait
251+
/// Wrapper over a [`embedded_io`](crate::eio::embedded_io)::[`Read`](crate::eio::Read) and a sliding buffer to implement the [`Flavor`] trait
252252
pub struct EIOReader<'de, T>
253253
where
254254
T: crate::eio::Read,
@@ -310,15 +310,15 @@ pub mod io {
310310
}
311311
}
312312

313-
/// Support for [std::io] traits
313+
/// Support for [`std::io`] traits
314314
#[allow(clippy::module_inception)]
315315
#[cfg(feature = "use-std")]
316316
pub mod io {
317317
use super::super::Flavor;
318318
use super::SlidingBuffer;
319319
use crate::{Error, Result};
320320

321-
/// Wrapper over a [std::io::Read] and a sliding buffer to implement the [Flavor] trait
321+
/// Wrapper over a [`std::io::Read`] and a sliding buffer to implement the [Flavor] trait
322322
pub struct IOReader<'de, T>
323323
where
324324
T: std::io::Read,
@@ -386,11 +386,11 @@ pub mod io {
386386
////////////////////////////////////////
387387

388388
/// This Cyclic Redundancy Check flavor applies [the CRC crate's `Algorithm`](https://docs.rs/crc/latest/crc/struct.Algorithm.html) struct on
389-
/// the serialized data. The flavor will check the CRC assuming that it has been appended to the bytes.
389+
/// the serialized data.
390390
///
391+
/// The flavor will check the CRC assuming that it has been appended to the bytes.
391392
/// CRCs are used for error detection when reading data back.
392-
///
393-
/// The `crc` feature requires enabling to use this module.
393+
/// Requires the `crc` feature.
394394
///
395395
/// More on CRCs: <https://en.wikipedia.org/wiki/Cyclic_redundancy_check>.
396396
#[cfg(feature = "use-crc")]

source/postcard/src/de/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ where
1818
Ok(t)
1919
}
2020

21-
/// Deserialize a message of type `T` from a cobs-encoded byte slice. The
22-
/// unused portion (if any) of the byte slice is not returned.
21+
/// Deserialize a message of type `T` from a cobs-encoded byte slice.
22+
///
23+
/// The unused portion (if any) of the byte slice is not returned.
2324
/// The used portion of the input slice is modified during deserialization (even if an error is returned).
2425
/// Therefore, if this is not desired, pass a clone of the original slice.
2526
pub fn from_bytes_cobs<'a, T>(s: &'a mut [u8]) -> Result<T>
@@ -30,8 +31,9 @@ where
3031
from_bytes::<T>(&s[..sz])
3132
}
3233

33-
/// Deserialize a message of type `T` from a cobs-encoded byte slice. The
34-
/// unused portion (if any) of the byte slice is returned for further usage.
34+
/// Deserialize a message of type `T` from a cobs-encoded byte slice.
35+
///
36+
/// The unused portion (if any) of the byte slice is returned for further usage.
3537
/// The used portion of the input slice is modified during deserialization (even if an error is returned).
3638
/// Therefore, if this is not desired, pass a clone of the original slice.
3739
pub fn take_from_bytes_cobs<'a, T>(s: &'a mut [u8]) -> Result<(T, &'a mut [u8])>
@@ -80,7 +82,7 @@ where
8082
Ok((t, deserializer.finalize()?))
8183
}
8284

83-
/// Deserialize a message of type `T` from a [std::io::Read].
85+
/// Deserialize a message of type `T` from a [`std::io::Read`].
8486
#[cfg(feature = "use-std")]
8587
pub fn from_io<'a, T, R>(val: (R, &'a mut [u8])) -> Result<(T, (R, &'a mut [u8]))>
8688
where
@@ -427,7 +429,7 @@ mod test_heapless {
427429
let x = ByteSliceStruct { bytes: &[0u8; 32] };
428430
let output: Vec<u8, 128> = to_vec(&x).unwrap();
429431
assert_eq!(output.len(), 33);
430-
let out: ByteSliceStruct = from_bytes(output.deref()).unwrap();
432+
let out: ByteSliceStruct<'_> = from_bytes(output.deref()).unwrap();
431433
assert_eq!(out, ByteSliceStruct { bytes: &[0u8; 32] });
432434
}
433435

@@ -488,7 +490,7 @@ mod test_heapless {
488490
output.deref()
489491
);
490492

491-
let out: RefStruct = from_bytes(output.deref()).unwrap();
493+
let out: RefStruct<'_> = from_bytes(output.deref()).unwrap();
492494
assert_eq!(
493495
out,
494496
RefStruct {
@@ -548,7 +550,7 @@ mod test_heapless {
548550

549551
let mut encode_buf = [0u8; 32];
550552
let sz = cobs::encode(output.deref(), &mut encode_buf);
551-
let out = from_bytes_cobs::<RefStruct>(&mut encode_buf[..sz]).unwrap();
553+
let out = from_bytes_cobs::<RefStruct<'_>>(&mut encode_buf[..sz]).unwrap();
552554

553555
assert_eq!(input, out);
554556
}

source/postcard/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use core::fmt::{Display, Formatter};
55
#[cfg_attr(feature = "use-defmt", derive(defmt::Format))]
66
#[non_exhaustive]
77
pub enum Error {
8-
/// This is a feature that PostCard will never implement
8+
/// This is a feature that postcard will never implement
99
WontImplement,
10-
/// This is a feature that Postcard intends to support, but does not yet
10+
/// This is a feature that postcard intends to support, but does not yet
1111
NotYetImplemented,
1212
/// The serialize buffer is full
1313
SerializeBufferFull,
@@ -25,7 +25,7 @@ pub enum Error {
2525
DeserializeBadUtf8,
2626
/// Found an Option discriminant that wasn't 0 or 1
2727
DeserializeBadOption,
28-
/// Found an enum discriminant that was > u32::max_value()
28+
/// Found an enum discriminant that was > `u32::MAX`
2929
DeserializeBadEnum,
3030
/// The original data was not well encoded
3131
DeserializeBadEncoding,
@@ -40,7 +40,7 @@ pub enum Error {
4040
}
4141

4242
impl Display for Error {
43-
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
43+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
4444
use Error::*;
4545
write!(
4646
f,

source/postcard/src/fixint.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use serde::{Deserialize, Serialize, Serializer};
1717

1818
/// Use with the `#[serde(with = "postcard::fixint::le")]` field attribute.
19+
///
1920
/// Disables varint serialization/deserialization for the specified integer
2021
/// field. The integer will always be serialized in the same way as a fixed
2122
/// size array, in **Little Endian** order on the wire.
@@ -53,9 +54,10 @@ pub mod le {
5354
}
5455
}
5556

57+
/// Disables varint serialization/deserialization for the specified integer field.
58+
///
5659
/// Use with the `#[serde(with = "postcard::fixint::be")]` field attribute.
57-
/// Disables varint serialization/deserialization for the specified integer
58-
/// field. The integer will always be serialized in the same way as a fixed
60+
/// The integer will always be serialized in the same way as a fixed
5961
/// size array, in **Big Endian** order on the wire.
6062
///
6163
/// ```rust

source/postcard/src/ser/flavors.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@ pub trait Flavor {
115115
/// such as a slice or a Vec of some sort.
116116
type Output;
117117

118-
/// The try_extend() trait method can be implemented when there is a more efficient way of processing
119-
/// multiple bytes at once, such as copying a slice to the output, rather than iterating over one byte
120-
/// at a time.
118+
/// Override this method when you want to customize processing
119+
/// multiple bytes at once, such as copying a slice to the output,
120+
/// rather than iterating over one byte at a time.
121121
#[inline]
122122
fn try_extend(&mut self, data: &[u8]) -> Result<()> {
123123
data.iter().try_for_each(|d| self.try_push(*d))
124124
}
125125

126-
/// The try_push() trait method can be used to push a single byte to be modified and/or stored
126+
/// Push a single byte to be modified and/or stored.
127127
fn try_push(&mut self, data: u8) -> Result<()>;
128128

129-
/// Finalize the serialization process
129+
/// Finalize the serialization process.
130130
fn finalize(self) -> Result<Self::Output>;
131131
}
132132

@@ -194,7 +194,7 @@ impl<'a> Flavor for Slice<'a> {
194194
}
195195
}
196196

197-
impl<'a> Index<usize> for Slice<'a> {
197+
impl Index<usize> for Slice<'_> {
198198
type Output = u8;
199199

200200
fn index(&self, idx: usize) -> &u8 {
@@ -204,15 +204,15 @@ impl<'a> Index<usize> for Slice<'a> {
204204
}
205205
}
206206

207-
impl<'a> IndexMut<usize> for Slice<'a> {
207+
impl IndexMut<usize> for Slice<'_> {
208208
fn index_mut(&mut self, idx: usize) -> &mut u8 {
209209
let len = (self.end as usize) - (self.start as usize);
210210
assert!(idx < len);
211211
unsafe { &mut *self.start.add(idx) }
212212
}
213213
}
214214

215-
/// Wrapper over a [`std::iter::Extend<u8>`] that implements the flavor trait
215+
/// Wrapper over a [`core::iter::Extend<u8>`] that implements the flavor trait
216216
pub struct ExtendFlavor<T> {
217217
iter: T,
218218
}
@@ -221,7 +221,7 @@ impl<T> ExtendFlavor<T>
221221
where
222222
T: core::iter::Extend<u8>,
223223
{
224-
/// Create a new [Self] flavor from a given [`std::iter::Extend<u8>`]
224+
/// Create a new [`Self`] flavor from a given [`core::iter::Extend<u8>`]
225225
pub fn new(iter: T) -> Self {
226226
Self { iter }
227227
}
@@ -241,7 +241,7 @@ where
241241

242242
#[inline(always)]
243243
fn try_extend(&mut self, b: &[u8]) -> Result<()> {
244-
self.iter.extend(b.iter().cloned());
244+
self.iter.extend(b.iter().copied());
245245
Ok(())
246246
}
247247

@@ -266,7 +266,7 @@ pub mod eio {
266266
where
267267
T: crate::eio::Write,
268268
{
269-
/// Create a new [Self] flavor from a given [`embedded_io Write`](crate::eio::Write)
269+
/// Create a new [`Self`] flavor from a given [`embedded_io Write`](crate::eio::Write)
270270
pub fn new(writer: T) -> Self {
271271
Self { writer }
272272
}
@@ -303,14 +303,14 @@ pub mod eio {
303303
}
304304
}
305305

306-
/// Support for the [std::io] traits
306+
/// Support for the [`std::io`] traits
307307
#[cfg(feature = "use-std")]
308308
pub mod io {
309309

310310
use super::Flavor;
311311
use crate::{Error, Result};
312312

313-
/// Wrapper over a [std::io::Write] that implements the flavor trait
313+
/// Wrapper over a [`std::io::Write`] that implements the flavor trait
314314
pub struct WriteFlavor<T> {
315315
writer: T,
316316
}
@@ -319,7 +319,7 @@ pub mod io {
319319
where
320320
T: std::io::Write,
321321
{
322-
/// Create a new [Self] flavor from a given [std::io::Write]
322+
/// Create a new [`Self`] flavor from a given [`std::io::Write`]
323323
pub fn new(writer: T) -> Self {
324324
Self { writer }
325325
}
@@ -377,7 +377,7 @@ mod heapless_vec {
377377
}
378378

379379
impl<const B: usize> HVec<B> {
380-
/// Create a new, currently empty, [heapless::Vec] to be used for storing serialized
380+
/// Create a new, currently empty, [`heapless::Vec`] to be used for storing serialized
381381
/// output data.
382382
pub fn new() -> Self {
383383
Self::default()
@@ -436,7 +436,7 @@ mod alloc_vec {
436436
use crate::Result;
437437
use alloc::vec::Vec;
438438

439-
/// The `AllocVec` flavor is a wrapper type around an [alloc::vec::Vec].
439+
/// The `AllocVec` flavor is a wrapper type around an [`alloc::vec::Vec`].
440440
///
441441
/// This type is only available when the (non-default) `alloc` feature is active
442442
#[derive(Default)]
@@ -446,7 +446,7 @@ mod alloc_vec {
446446
}
447447

448448
impl AllocVec {
449-
/// Create a new, currently empty, [alloc::vec::Vec] to be used for storing serialized
449+
/// Create a new, currently empty, [`alloc::vec::Vec`] to be used for storing serialized
450450
/// output data.
451451
pub fn new() -> Self {
452452
Self::default()
@@ -564,11 +564,11 @@ where
564564
////////////////////////////////////////
565565

566566
/// This Cyclic Redundancy Check flavor applies [the CRC crate's `Algorithm`](https://docs.rs/crc/latest/crc/struct.Algorithm.html) struct on
567-
/// the serialized data. The output of this flavor receives the CRC appended to the bytes.
567+
/// the serialized data.
568568
///
569+
/// The output of this flavor receives the CRC appended to the bytes.
569570
/// CRCs are used for error detection when reading data back.
570-
///
571-
/// The `crc` feature requires enabling to use this module.
571+
/// Requires the `crc` feature.
572572
///
573573
/// More on CRCs: <https://en.wikipedia.org/wiki/Cyclic_redundancy_check>.
574574
#[cfg(feature = "use-crc")]

0 commit comments

Comments
 (0)