Skip to content

Commit 4e800d7

Browse files
committed
image-rs: change RegistryHandler::from_str to from_vec
This little refactor helps the higher caller to handle raised errors. Signed-off-by: Xynnn007 <[email protected]>
1 parent 311647d commit 4e800d7

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

image-rs/src/registry/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,14 @@ enum MatchResult {
112112
Unmatched,
113113
}
114114

115-
impl FromStr for RegistryHandler {
116-
type Err = anyhow::Error;
117-
118-
fn from_str(s: &str) -> Result<Self, Self::Err> {
119-
let mut config: Config = toml::from_str(s)?;
115+
impl RegistryHandler {
116+
pub fn from_vec(s: Vec<u8>) -> Result<Self> {
117+
let registry_configuration = String::from_utf8(s)?;
118+
let mut config: Config = toml::from_str(&registry_configuration)?;
120119
config.validate_and_tidy()?;
121120
Ok(Self { config })
122121
}
123-
}
124122

125-
impl RegistryHandler {
126123
fn generate_unqualified_search_tasks(&self, reference: &Reference) -> Vec<ImagePullTask> {
127124
let mut tasks = Vec::new();
128125

@@ -371,7 +368,7 @@ location = "docker.io"
371368
location = "123456.mirror.aliyuncs.com"
372369
"#;
373370

374-
RegistryHandler::from_str(config).unwrap()
371+
RegistryHandler::from_vec(config.as_bytes().to_vec()).unwrap()
375372
}
376373

377374
#[test]

0 commit comments

Comments
 (0)