Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement From<NtStatusError> for RegistryError to simplify a small piece of code #17

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions registry/src/regconfighelper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub enum RegistryError {
Input(String),
}

impl From<NtStatusError> for RegistryError {
fn from(err: NtStatusError) -> Self {
RegistryError::NtStatus(err)
}
}

impl Display for RegistryError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down Expand Up @@ -85,12 +91,7 @@ pub fn config_set(config: &RegistryConfig) -> Result<(String, bool), RegistryErr
match config.value_data.as_ref() {
Some(value_data) => {
reg_result.value_data = Some(value_data.clone());
match reg_key.set_value(value_name, &convert_configreg_data(value_data)) {
Ok(_) => {},
Err(err) => {
return Err(RegistryError::NtStatus(err));
}
}
reg_key.set_value(value_name, &convert_configreg_data(value_data))?;
},
None => {
// just verify that the value exists
Expand Down Expand Up @@ -191,14 +192,7 @@ fn open_or_create_key(key_path: &str) -> Result<RegistryKey, RegistryError> {
let (parent_key, subkeys) = get_valid_parent_key_and_subkeys(key_path)?;
let mut current_key = parent_key;
for subkey in subkeys {
match current_key.create_key(subkey) {
Ok(key) => {
current_key = key;
},
Err(err) => {
return Err(RegistryError::NtStatus(err));
}
}
current_key = current_key.create_key(subkey)?;
}
reg_key = current_key;
},
Expand Down