Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enhance cross-version support #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords = ["serialization", "version"]
categories = ["encoding"]

[dependencies]
semver = "1.0.16"
serde = "1.0.27"
serde_derive = "1.0.27"
bincode = "1.2.1"
Expand All @@ -22,5 +23,9 @@ proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0.13", features=["default","full"]}

[dev-dependencies]
byteorder = "1.4.3"
versionize_derive = "0.1.4"

[badges]
maintenance = { status = "experimental" }
42 changes: 18 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ pub enum VersionizeError {
StringLength(usize),
/// Vector length exceeded.
VecLength(usize),
/// Unsupported version.
UnsuportVersion(String),
/// Multiple version
MultipleVersion(String, String, String),
/// Version parse error.
ParseVersion(String, String),
/// Not found crate.
NotFoundCrate(String),
}

impl std::fmt::Display for VersionizeError {
Expand All @@ -82,6 +90,14 @@ impl std::fmt::Display for VersionizeError {
bad_len,
primitives::MAX_VEC_SIZE
),
UnsuportVersion(ver) => write!(f, "{} version is NOT supported.", ver),
MultipleVersion(rcrate, a, b) => write!(
f,
"There are multiple version {}, {} in {} crate.",
a, b, rcrate,
),
ParseVersion(ver, err) => write!(f, "Parse version {} failed. {}", ver, err),
NotFoundCrate(pkg) => write!(f, "Not found crate {}.", pkg),
}
}
}
Expand Down Expand Up @@ -136,35 +152,13 @@ pub type VersionizeResult<T> = std::result::Result<T, VersionizeError>;
pub trait Versionize {
/// Serializes `self` to `target_verion` using the specficifed `writer` and
/// `version_map`.
fn serialize<W: Write>(
&self,
writer: &mut W,
version_map: &VersionMap,
target_version: u16,
) -> VersionizeResult<()>;
fn serialize<W: Write>(&self, writer: W, version_map: &mut VersionMap) -> VersionizeResult<()>;

/// Returns a new instance of `Self` by deserializing from `source_version`
/// using the specficifed `reader` and `version_map`.
fn deserialize<R: Read>(
reader: &mut R,
version_map: &VersionMap,
source_version: u16,
) -> VersionizeResult<Self>
fn deserialize<R: Read>(reader: R, version_map: &VersionMap) -> VersionizeResult<Self>
where
Self: Sized;

/// Returns the `Self` type id.
/// The returned ID represents a globally unique identifier for a type.
/// It is required by the `VersionMap` implementation.
fn type_id() -> std::any::TypeId
where
Self: 'static,
{
TypeId::of::<Self>()
}

/// Returns latest `Self` version number.
fn version() -> u16;
}

#[cfg(test)]
Expand Down
Loading