diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-08-23 07:46:53 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-09-07 11:37:47 -0400 |
| commit | f702bd6a529ce9d2e311ea0254a04228a4a2f129 (patch) | |
| tree | 0bb022359f5fd9b0ec5d81fe0fa4f5a5a97b011a /src/libserialize | |
| parent | c67d518b0d92785323f2c9c94dda25273821b47b (diff) | |
| download | rust-f702bd6a529ce9d2e311ea0254a04228a4a2f129.tar.gz rust-f702bd6a529ce9d2e311ea0254a04228a4a2f129.zip | |
rewrite constants to use NewType::MAX instead of u32::MAX
Also, adjust the MAX to be `u32::MAX - 1`, leaving room for `u32::MAX` to become a sentinel value in the future.
Diffstat (limited to 'src/libserialize')
| -rw-r--r-- | src/libserialize/serialize.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 60bb5a0fec2..416be50bfe9 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -361,6 +361,18 @@ impl Decodable for u32 { } } +impl Encodable for ::std::num::NonZeroU32 { + fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_u32(self.get()) + } +} + +impl Decodable for ::std::num::NonZeroU32 { + fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> { + d.read_u32().map(|d| ::std::num::NonZeroU32::new(d).unwrap()) + } +} + impl Encodable for u64 { fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u64(*self) @@ -895,3 +907,4 @@ impl<T: UseSpecializedDecodable> Decodable for T { impl<'a, T: ?Sized + Encodable> UseSpecializedEncodable for &'a T {} impl<T: ?Sized + Encodable> UseSpecializedEncodable for Box<T> {} impl<T: Decodable> UseSpecializedDecodable for Box<T> {} + |
