diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-09-02 07:48:37 +0200 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-09-30 09:51:49 +0200 |
| commit | 588ed766cf6f22c4a3bdf90ae00c775799fb75d2 (patch) | |
| tree | 657d610f8f7f4d0b675d5292386253f63e5e67e3 | |
| parent | 2a9fa6f391e2e734af608eb93440c2f21fca6819 (diff) | |
| download | mullvadvpn-588ed766cf6f22c4a3bdf90ae00c775799fb75d2.tar.xz mullvadvpn-588ed766cf6f22c4a3bdf90ae00c775799fb75d2.zip | |
Add access method update_builtin function
This access method's update function was rewritten to introduce
validation before updating the relevant access method, and therefore
when the function is used the potential error must be handled.
However, we still need to be able to update an access method
without any error handling, such as setting the Direct access method
as enabled, and that's where this new update_builtin function comes in.
| -rw-r--r-- | mullvad-types/src/access_method.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mullvad-types/src/access_method.rs b/mullvad-types/src/access_method.rs index 342b8ffcaf..8ba50c91c3 100644 --- a/mullvad-types/src/access_method.rs +++ b/mullvad-types/src/access_method.rs @@ -93,6 +93,30 @@ impl Settings { Ok(updated) } + /// Update an existing builtin [`AccessMethodSetting`] chosen by + /// `predicate`, in a closure `f`, saving the result to `self`. + /// + /// Returns a bool to indicate whether some [`AccessMethodSetting`] was + /// updated. + pub fn update_builtin( + &mut self, + predicate: impl Fn(&AccessMethodSetting) -> bool, + f: impl FnOnce(&mut AccessMethodSetting), + ) -> bool { + let mut updated = false; + + if let Some(access_method) = self + .iter_mut() + .find(|setting| setting.is_builtin() && predicate(setting)) + { + f(access_method); + + updated = true; + } + + updated + } + /// Remove all custom access methods. pub fn clear_custom(&mut self) { self.custom.clear(); |
