Skip to content

Commit

Permalink
refactor: apply linter's advices
Browse files Browse the repository at this point in the history
Signed-off-by: David Bernard <david.bernard.31@gmail.com>
  • Loading branch information
davidB committed Mar 3, 2024
1 parent 94b3e6a commit f3f353b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
6 changes: 3 additions & 3 deletions cdevents-sdk/src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl TryFrom<String> for Uri {
}
}

impl ToString for Uri {
fn to_string(&self) -> String {
self.0.as_str().to_owned()//into_string()
impl std::fmt::Display for Uri {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.as_str().fmt(f)
}
}

Expand Down
6 changes: 3 additions & 3 deletions cdevents-sdk/src/uri_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl TryFrom<String> for UriReference {
}
}

impl ToString for UriReference {
fn to_string(&self) -> String {
self.0.as_str().to_owned()//into_string()
impl std::fmt::Display for UriReference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.as_str().fmt(f)
}
}

Expand Down
27 changes: 4 additions & 23 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod version;

use anyhow::{Context, Result};
use clap::Parser;
use cruet::Inflector;
Expand All @@ -6,7 +8,8 @@ use handlebars::{DirectorySourceOptions, Handlebars};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::{cmp::Ordering, collections::HashMap, fs, path::PathBuf};
use std::{collections::HashMap, fs, path::PathBuf};
use version::Version;

/// generator of part of the rust code of cdevents from spec
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -195,28 +198,6 @@ struct VariantInfo {
spec_version: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
struct Version {
major: u8,
minor: u8,
patch: u8,
modifier: String,
}

impl Ord for Version {
fn cmp(&self, other: &Self) -> Ordering {
let mut r = self.major.cmp(&other.major);
if r.is_eq() {
r = self.minor.cmp(&other.minor);
}
if r.is_eq() {
r = self.patch.cmp(&other.patch);
}
//TODO compare modifier with semantic ("snapshot", "draft", "alpha", "beta", "rc", "ga", "")
r
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
struct StructDef {
type_info: TypeInfo,
Expand Down
31 changes: 31 additions & 0 deletions generator/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::cmp::Ordering;

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct Version {
pub(crate) major: u8,
pub(crate) minor: u8,
pub(crate) patch: u8,
pub(crate) modifier: String,
}

impl PartialOrd for Version {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Version {
fn cmp(&self, other: &Self) -> Ordering {
let mut r = self.major.cmp(&other.major);
if r.is_eq() {
r = self.minor.cmp(&other.minor);
}
if r.is_eq() {
r = self.patch.cmp(&other.patch);
}
//TODO compare modifier with semantic ("snapshot", "draft", "alpha", "beta", "rc", "ga", "")
r
}
}

0 comments on commit f3f353b

Please sign in to comment.