more idiomatic and shorter

This commit is contained in:
Alex Auvolat 2023-01-03 16:00:19 +01:00
parent 33f25d26c7
commit c106304b9c
No known key found for this signature in database
GPG key ID: 0E496D15096376BE

View file

@ -18,7 +18,7 @@ pub trait Migrate: Serialize + for<'de> Deserialize<'de> + 'static {
/// Decode an encoded version of this type, going through a migration if necessary. /// Decode an encoded version of this type, going through a migration if necessary.
fn decode(bytes: &[u8]) -> Option<Self> { fn decode(bytes: &[u8]) -> Option<Self> {
let marker_len = Self::VERSION_MARKER.len(); let marker_len = Self::VERSION_MARKER.len();
if bytes.len() >= marker_len && &bytes[..marker_len] == Self::VERSION_MARKER { if bytes.get(..marker_len) == Some(Self::VERSION_MARKER) {
if let Ok(value) = rmp_serde::decode::from_read_ref::<_, Self>(&bytes[marker_len..]) { if let Ok(value) = rmp_serde::decode::from_read_ref::<_, Self>(&bytes[marker_len..]) {
return Some(value); return Some(value);
} }