summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs2
-rw-r--r--src/stackexchange/local_storage.rs10
-rw-r--r--src/term.rs2
-rw-r--r--src/utils.rs15
4 files changed, 14 insertions, 15 deletions
diff --git a/src/error.rs b/src/error.rs
index ec76943..05ba004 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -14,8 +14,6 @@ pub enum Error {
SerdeJson(#[from] serde_json::Error),
#[error("SerdeYaml error: {0}")]
SerdeYaml(#[from] serde_yaml::Error),
- #[error("IO error: {0}")]
- IO(#[from] std::io::Error),
#[error("Futures Join error : {0}")]
JoinError(#[from] tokio::task::JoinError),
#[error("File `{}` is malformed; try removing it", .0.display())]
diff --git a/src/stackexchange/local_storage.rs b/src/stackexchange/local_storage.rs
index d5adeb2..5874611 100644
--- a/src/stackexchange/local_storage.rs
+++ b/src/stackexchange/local_storage.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::fs;
-use std::path::PathBuf;
+use std::path::Path;
use crate::config::Config;
use crate::error::{Error, Result};
@@ -14,21 +14,21 @@ pub struct LocalStorage {
}
impl LocalStorage {
- fn fetch_local_sites(filename: &PathBuf) -> Result<Option<Vec<Site>>> {
+ fn fetch_local_sites(filename: &Path) -> Result<Option<Vec<Site>>> {
if let Some(file) = utils::open_file(filename)? {
return serde_json::from_reader(file)
- .map_err(|_| Error::MalformedFile(filename.clone()));
+ .map_err(|_| Error::MalformedFile(filename.to_path_buf()));
}
Ok(None)
}
- fn store_local_sites(filename: &PathBuf, sites: &[Site]) -> Result<()> {
+ fn store_local_sites(filename: &Path, sites: &[Site]) -> Result<()> {
let file = utils::create_file(filename)?;
serde_json::to_writer(file, sites)?;
Ok(())
}
- async fn init_sites(filename: &PathBuf, update: bool) -> Result<Vec<Site>> {
+ async fn init_sites(filename: &Path, update: bool) -> Result<Vec<Site>> {
if !update {
if let Some(sites) = Self::fetch_local_sites(filename)? {
return Ok(sites);
diff --git a/src/term.rs b/src/term.rs
index ff537c4..44544aa 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -3,7 +3,7 @@ use crossterm::style::{Color, Print};
use crossterm::terminal::ClearType;
use crossterm::{cursor, execute, terminal};
use futures::Future;
-use std::io::{stderr, Write};
+use std::io::stderr;
use termimad::{CompoundStyle, LineStyle, MadSkin};
use tokio::sync::{
oneshot,
diff --git a/src/utils.rs b/src/utils.rs
index d1ffed8..fcac095 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,22 +1,23 @@
use crate::error::{Error, PermissionType, Result};
use std::fs::File;
use std::io::ErrorKind;
-use std::path::PathBuf;
+use std::path::Path;
-pub fn open_file(filename: &PathBuf) -> Result<Option<File>> {
+pub fn open_file(filename: &Path) -> Result<Option<File>> {
File::open(filename).map(Some).or_else(|e| match e {
e if e.kind() == ErrorKind::NotFound => Ok(None),
- e if e.kind() == ErrorKind::PermissionDenied => {
- Err(Error::Permissions(PermissionType::Read, filename.clone()))
- }
+ e if e.kind() == ErrorKind::PermissionDenied => Err(Error::Permissions(
+ PermissionType::Read,
+ filename.to_path_buf(),
+ )),
e => Err(Error::from(e)),
})
}
-pub fn create_file(filename: &PathBuf) -> Result<File> {
+pub fn create_file(filename: &Path) -> Result<File> {
File::create(filename).map_err(|e| {
if e.kind() == ErrorKind::PermissionDenied {
- Error::Permissions(PermissionType::Write, filename.clone())
+ Error::Permissions(PermissionType::Write, filename.to_path_buf())
} else {
Error::from(e)
}