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

Add serde support as a feature #10

Merged
merged 1 commit into from
Nov 18, 2021
Merged
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
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