Skip to content

Commit ae7b978

Browse files
committed
common: move InputFormat
1 parent 882986d commit ae7b978

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

src/common/input_format.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use anyhow::{anyhow, Result};
2+
use std::str::FromStr;
3+
4+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5+
#[non_exhaustive]
6+
pub enum InputFormat {
7+
Xml,
8+
#[cfg(feature = "yaml")]
9+
Yaml,
10+
#[cfg(feature = "json")]
11+
Json,
12+
}
13+
14+
impl FromStr for InputFormat {
15+
type Err = anyhow::Error;
16+
fn from_str(s: &str) -> Result<Self, Self::Err> {
17+
match s {
18+
"svd" | "SVD" | "xml" | "XML" => Ok(Self::Xml),
19+
#[cfg(feature = "yaml")]
20+
"yml" | "yaml" | "YAML" => Ok(Self::Yaml),
21+
#[cfg(feature = "json")]
22+
"json" | "JSON" => Ok(Self::Json),
23+
_ => Err(anyhow!("Unknown input file format")),
24+
}
25+
}
26+
}

src/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod input_format;
12
pub mod str_utils;
23
pub mod svd_reader;
34
pub mod svd_utils;

src/convert/convert_cli.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,10 @@ use std::str::FromStr;
44
use std::{fs::File, path::Path};
55
use svd_rs::Device;
66

7+
pub use crate::common::input_format::InputFormat;
78
use crate::get_encoder_config;
89
pub use crate::ConfigFormat;
910

10-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11-
#[non_exhaustive]
12-
pub enum InputFormat {
13-
Xml,
14-
#[cfg(feature = "yaml")]
15-
Yaml,
16-
#[cfg(feature = "json")]
17-
Json,
18-
}
19-
20-
impl FromStr for InputFormat {
21-
type Err = anyhow::Error;
22-
fn from_str(s: &str) -> Result<Self, Self::Err> {
23-
match s {
24-
"svd" | "SVD" | "xml" | "XML" => Ok(Self::Xml),
25-
#[cfg(feature = "yaml")]
26-
"yml" | "yaml" | "YAML" => Ok(Self::Yaml),
27-
#[cfg(feature = "json")]
28-
"json" | "JSON" => Ok(Self::Json),
29-
_ => Err(anyhow!("Unknown input file format")),
30-
}
31-
}
32-
}
33-
3411
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3512
#[non_exhaustive]
3613
pub enum OutputFormat {

src/patch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod register;
3636
mod yaml_ext;
3737
use yaml_ext::{AsType, GetVal, ToYaml};
3838

39-
use crate::convert::convert_cli::InputFormat;
39+
use crate::common::input_format::InputFormat;
4040
use crate::get_encoder_config;
4141

4242
const VAL_LVL: ValidateLevel = ValidateLevel::Weak;

0 commit comments

Comments
 (0)