Skip to content

Commit

Permalink
Merge pull request #10 from mt-caret/serde
Browse files Browse the repository at this point in the history
Add serde support as a feature
  • Loading branch information
gngeorgiev authored Nov 18, 2021
2 parents 4efeb9f + 27127d2 commit 31ae4cb
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 1 deletion.
56 changes: 56 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ travis-ci = { repository = "gngeorgiev/semver_rs", branch = "master" }
[dependencies]
lazy_static = "1.1"
regex = "1"
unicase = "2.3"
unicase = "2.3"
serde = { version = "1.0", features = ["derive"], optional = true }

[features]
default = []
4 changes: 4 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::error::Error;

use std::marker::PhantomData;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Allows building an [Options](crate::Options) instance.
/// ## Example
/// ```
Expand Down Expand Up @@ -44,6 +47,7 @@ impl OptionsBuilder {
/// # Ok::<(), Error>(())
/// ```
#[derive(Default, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Options {
/// Be more forgiving about not-quite-valid semver strings.
/// Any resulting output will always be 100% strict compliant.
Expand Down
4 changes: 4 additions & 0 deletions src/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::version::Version;
use std::cmp::Ordering;
use std::fmt;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// ComparatorPair is a simple struct that can hold two comparators
/// it knows how to format its Comparators
#[derive(Debug)]
Expand All @@ -32,6 +35,7 @@ impl fmt::Display for ComparatorPair {
/// A `Comparator` is composed of an [Operator](crate::operator::Operator) and a [Version](create::version::Version).
/// Comparators are the building blocks of [Range](crate::range::Range)s
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Comparator {
pub operator: Operator,
pub version: Version,
Expand Down
4 changes: 4 additions & 0 deletions src/operator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::fmt;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Operator {
Gt,
Lt,
Expand Down
4 changes: 4 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use crate::util::{is_any_version, match_at_index_str};
use crate::version::Version;
use std::borrow::Cow;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A `version range` is a set of `comparators` which specify versions that satisfy the `range`.
/// A comparator is composed of an operator and a version. The set of primitive operators is:
///
Expand All @@ -34,6 +37,7 @@ use std::borrow::Cow;
///
/// The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`, `1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Range {
pub(crate) comparators: Vec<Vec<Comparator>>,

Expand Down
4 changes: 4 additions & 0 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ use crate::util::compare_identifiers;

use std::{cmp::Ordering, fmt, str};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A `version` is described by the `v2.0.0` specification found at [semver](https://semver.org/).
///
/// A leading `=` or `v` character is stripped off and ignored.
#[derive(Default, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Version {
pub major: i32,
pub minor: i32,
Expand Down

0 comments on commit 31ae4cb

Please sign in to comment.