Skip to main content

semver_cargo/models/
config.rs

1use derive_getters::Getters;
2use semver_common::Alert;
3use serde::{Deserialize, Serialize};
4use std::convert::From;
5use std::str::FromStr;
6
7fn default_true() -> bool {
8    true
9}
10
11fn default_false() -> bool {
12    false
13}
14
15#[derive(Serialize, Deserialize, Getters, Clone)]
16pub struct Config {
17    /// A flag specifying whether to set the version in the Cargo.toml file.
18    #[serde(default = "default_true")]
19    set_version: bool,
20
21    /// A flag specifying whether to publish the crate to crates.io.
22    #[serde(default = "default_false")]
23    publish: bool,
24
25    /// A flag specifying whether to run this plugin even if the version was no updated.
26    #[serde(default = "default_false")]
27    act_on_no_update: bool,
28}
29
30impl FromStr for Config {
31    type Err = Alert;
32
33    fn from_str(s: &str) -> Result<Self, Self::Err> {
34        let config: Config = serde_json::from_str(s)?;
35        Ok(config)
36    }
37}
38
39impl<T> From<T> for Config
40where
41    T: ToString,
42{
43    fn from(value: T) -> Self {
44        Self::from_str(&value.to_string()).unwrap()
45    }
46}