-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac2e162
commit 812cc60
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::Result; | ||
use geekorm::{prelude::*, GEEKORM_BANNER, GEEKORM_VERSION}; | ||
|
||
#[derive(Table, Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
struct Project { | ||
#[geekorm(primary_key, auto_increment)] | ||
pub id: PrimaryKey<i32>, | ||
|
||
#[geekorm(unique)] | ||
pub name: String, | ||
|
||
pub version: semver::Version, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
println!("{} v{}\n", GEEKORM_BANNER, GEEKORM_VERSION); | ||
|
||
let gorm = Project::new("geekorm", semver::Version::parse(GEEKORM_VERSION).unwrap()); | ||
println!("Project :: {:?}", gorm); | ||
|
||
let req = semver::VersionReq::parse(">=0.4.0, <1.0.0").unwrap(); | ||
|
||
assert!(req.matches(&gorm.version)); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//! # Implementations of `From` trait for semver types. | ||
//! | ||
//! ```rust | ||
//! # #[cfg(feature = "semver")] { | ||
//! use geekorm::prelude::*; | ||
//! use semver::{Version, VersionReq}; | ||
//! | ||
//! #[derive(Table, Clone, serde::Serialize, serde::Deserialize)] | ||
//! struct Project { | ||
//! #[geekorm(primary_key, auto_increment)] | ||
//! id: PrimaryKey<i32>, | ||
//! /// Name of the project | ||
//! #[geekorm(unique)] | ||
//! name: String, | ||
//| /// Version | ||
//! version: Version, | ||
//! /// Required Version | ||
//! requirement: VersionReq, | ||
//! } | ||
//! | ||
//! // Create a new Project with a semver Version | ||
//! let project = Project::new( | ||
//! "geekorm", | ||
//! Version::parse("1.0.0").unwrap(), | ||
//! VersionReq::parse(">=0.6, <1.2.3").unwrap(), | ||
//! ); | ||
//! | ||
//! # assert!(project.requirement.matches(&project.version)); | ||
//! | ||
//! # } | ||
//! ``` | ||
use super::Value; | ||
use semver::{Version, VersionReq}; | ||
|
||
impl From<Version> for Value { | ||
fn from(value: Version) -> Self { | ||
Value::Text(value.to_string()) | ||
} | ||
} | ||
|
||
impl From<&Version> for Value { | ||
fn from(value: &Version) -> Self { | ||
Value::Text(value.to_string()) | ||
} | ||
} | ||
|
||
impl From<Value> for Version { | ||
fn from(value: Value) -> Self { | ||
// TODO: This unwrap isn't great... | ||
Version::parse(&value.to_string()).unwrap() | ||
} | ||
} | ||
|
||
impl From<VersionReq> for Value { | ||
fn from(value: VersionReq) -> Self { | ||
Value::Text(value.to_string()) | ||
} | ||
} | ||
impl From<&VersionReq> for Value { | ||
fn from(value: &VersionReq) -> Self { | ||
Value::Text(value.to_string()) | ||
} | ||
} | ||
|
||
impl From<Value> for VersionReq { | ||
fn from(value: Value) -> Self { | ||
// TODO: This unwrap isn't great | ||
VersionReq::parse(&value.to_string()).unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters