summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2024-11-27 14:41:55 +0100
committerDavid Lönnhager <david.l@mullvad.net>2024-12-02 16:00:38 +0100
commite07c12a5f14a11051fa086c97cc22413e431a1c8 (patch)
treed4c70f405fd178d52dce4bf4418b919cf9e15837
parent8bc1412be0d5d9b229149a473e6bfb3901d9b59b (diff)
downloadmullvadvpn-e07c12a5f14a11051fa086c97cc22413e431a1c8.tar.xz
mullvadvpn-e07c12a5f14a11051fa086c97cc22413e431a1c8.zip
Make address cache constructor infallible
-rw-r--r--mullvad-api/src/address_cache.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/mullvad-api/src/address_cache.rs b/mullvad-api/src/address_cache.rs
index dfa586daf4..a48db1a0e2 100644
--- a/mullvad-api/src/address_cache.rs
+++ b/mullvad-api/src/address_cache.rs
@@ -31,30 +31,28 @@ pub struct AddressCache {
impl AddressCache {
/// Initialize cache using the hardcoded address, and write changes to `write_path`.
- pub fn new(write_path: Option<Box<Path>>) -> Result<Self, Error> {
+ pub fn new(write_path: Option<Box<Path>>) -> Self {
Self::new_inner(API.address(), write_path)
}
pub fn with_static_addr(address: SocketAddr) -> Self {
Self::new_inner(address, None)
- .expect("Failed to construct an address cache from a static address")
}
/// Initialize cache using `read_path`, and write changes to `write_path`.
pub async fn from_file(read_path: &Path, write_path: Option<Box<Path>>) -> Result<Self, Error> {
log::debug!("Loading API addresses from {}", read_path.display());
- Self::new_inner(read_address_file(read_path).await?, write_path)
+ Ok(Self::new_inner(read_address_file(read_path).await?, write_path))
}
- fn new_inner(address: SocketAddr, write_path: Option<Box<Path>>) -> Result<Self, Error> {
+ fn new_inner(address: SocketAddr, write_path: Option<Box<Path>>) -> Self {
let cache = AddressCacheInner::from_address(address);
log::debug!("Using API address: {}", cache.address);
- let address_cache = Self {
+ Self {
inner: Arc::new(Mutex::new(cache)),
write_path: write_path.map(Arc::from),
- };
- Ok(address_cache)
+ }
}
/// Returns the address if the hostname equals `API.host`. Otherwise, returns `None`.