Use `Result<_, io::Error>` over `io::Result<_>`
authorMatt Corallo <git@bluematt.me>
Wed, 27 Sep 2023 22:26:57 +0000 (22:26 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 28 Sep 2023 02:41:51 +0000 (02:41 +0000)
Personally I've always found the overload of a prelude enum to be
confusing, and never bothered to handle it properly in bindings as
a result. To avoid needing to do so now, we simply move the
newly-introduced `io::Result` usages over to
`Result<_, io::Error>`.

lightning/src/util/persist.rs

index dbe3ee8161ef4498904709a0c7ad5080d1bcb7ac..4335a124d4dad3236d7447b0835a60b7a8c97c62 100644 (file)
@@ -16,7 +16,7 @@ use bitcoin::{BlockHash, Txid};
 
 use crate::{io, log_error};
 use crate::alloc::string::ToString;
-use crate::prelude::{Vec, String};
+use crate::prelude::*;
 
 use crate::chain;
 use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
@@ -98,11 +98,11 @@ pub trait KVStore {
        /// `namespace` and `sub_namespace`.
        ///
        /// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
-       fn read(&self, namespace: &str, sub_namespace: &str, key: &str) -> io::Result<Vec<u8>>;
+       fn read(&self, namespace: &str, sub_namespace: &str, key: &str) -> Result<Vec<u8>, io::Error>;
        /// Persists the given data under the given `key`.
        ///
        /// Will create the given `namespace` and `sub_namespace` if not already present in the store.
-       fn write(&self, namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> io::Result<()>;
+       fn write(&self, namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> Result<(), io::Error>;
        /// Removes any data that had previously been persisted under the given `key`.
        ///
        /// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
@@ -117,12 +117,12 @@ pub trait KVStore {
        ///
        /// Returns successfully if no data will be stored for the given `namespace`, `sub_namespace`, and
        /// `key`, independently of whether it was present before its invokation or not.
-       fn remove(&self, namespace: &str, sub_namespace: &str, key: &str, lazy: bool) -> io::Result<()>;
+       fn remove(&self, namespace: &str, sub_namespace: &str, key: &str, lazy: bool) -> Result<(), io::Error>;
        /// Returns a list of keys that are stored under the given `sub_namespace` in `namespace`.
        ///
        /// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
        /// returned keys. Returns an empty list if `namespace` or `sub_namespace` is unknown.
-       fn list(&self, namespace: &str, sub_namespace: &str) -> io::Result<Vec<String>>;
+       fn list(&self, namespace: &str, sub_namespace: &str) -> Result<Vec<String>, io::Error>;
 }
 
 /// Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.