Skip to content

Commit

Permalink
Fix features
Browse files Browse the repository at this point in the history
  • Loading branch information
DelSkayn committed Aug 15, 2024
1 parent f39831b commit 2bea824
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 32 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = ["derive"]
[features]
default = []


[dependencies]
chrono = { version = "0.4.26", features = ["serde"], optional = true }
derive = { version = "0.8.0", package = "revision-derive", path = "derive" }
Expand Down
29 changes: 4 additions & 25 deletions src/implementations/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,14 @@ use rust_decimal::Decimal;
impl Revisioned for Decimal {
#[inline]
fn serialize_revisioned<W: std::io::Write>(&self, writer: &mut W) -> Result<(), Error> {
writer
.write_all(self.serialize().as_slice())
.map_err(|e| Error::Io(e.raw_os_error().unwrap_or(0)))
writer.write_all(self.serialize().as_slice()).map_err(Error::Io)
}

#[inline]
fn deserialize_revisioned<R: std::io::Read>(reader: &mut R) -> Result<Self, Error> {
let mut v = vec![0u8; 16];
reader
.read_exact(v.as_mut_slice())
.map_err(|e| Error::Io(e.raw_os_error().unwrap_or(0)))?;
Ok(Decimal::deserialize([
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
v.remove(0),
]))
let mut b = [0u8; 16];
reader.read_exact(&mut b).map_err(Error::Io)?;
Ok(Decimal::deserialize(b))
}

fn revision() -> u16 {
Expand Down
4 changes: 2 additions & 2 deletions src/implementations/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use super::super::Error;
use super::super::Revisioned;
use super::string::serialize_str;
use super::vecs::serialize_slice;
use regex::Regex;

impl Revisioned for Regex {
#[inline]
fn serialize_revisioned<W: std::io::Write>(&self, writer: &mut W) -> Result<(), Error> {
serialize_str(writer, self.as_str())
serialize_slice(self.as_str().as_bytes(), writer)
}

#[inline]
Expand Down
9 changes: 4 additions & 5 deletions src/implementations/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

use super::super::Error;
use super::super::Revisioned;
use super::vecs::serialize_slice;
use uuid::Uuid;

impl Revisioned for Uuid {
#[inline]
fn serialize_revisioned<W: std::io::Write>(&self, writer: &mut W) -> Result<(), Error> {
writer.write_all(self.as_bytes()).map_err(|e| Error::Io(e.raw_os_error().unwrap_or(0)))
serialize_slice(self.as_bytes(), writer)
}

#[inline]
fn deserialize_revisioned<R: std::io::Read>(reader: &mut R) -> Result<Self, Error> {
let mut v = vec![0u8; 16];
reader
.read_exact(v.as_mut_slice())
.map_err(|e| Error::Io(e.raw_os_error().unwrap_or(0)))?;
let mut v = [0u8; 16];
reader.read_exact(&mut v).map_err(Error::Io)?;
Uuid::from_slice(&v).map_err(|_| Error::Deserialize("invalid uuid".to_string()))
}

Expand Down

0 comments on commit 2bea824

Please sign in to comment.