aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortilpner2020-09-10 23:02:54 +0200
committertilpner2020-09-10 23:02:54 +0200
commit67bf17e99d7fc22d051faee001a95f5a7ac6e1d5 (patch)
treeb4d758a0600e4424a23b44d0efc5f55f7380bf3a
parent124e48e238a19c03d7434f7f0e6fe3ef1cfdcfa6 (diff)
downloadrpb-s3-67bf17e99d7fc22d051faee001a95f5a7ac6e1d5.tar.gz
rpb-s3-67bf17e99d7fc22d051faee001a95f5a7ac6e1d5.tar.xz
rpb-s3-67bf17e99d7fc22d051faee001a95f5a7ac6e1d5.zip
Minor style improvements
-rw-r--r--src/base62.rs4
-rw-r--r--src/main.rs18
2 files changed, 9 insertions, 13 deletions
diff --git a/src/base62.rs b/src/base62.rs
index a87503f..50b163b 100644
--- a/src/base62.rs
+++ b/src/base62.rs
@@ -1,5 +1,5 @@
pub const BASE: u8 = 62;
-pub const ALPHABET: &'static [u8; BASE as usize] =
+pub const ALPHABET: &[u8; BASE as usize] =
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
pub fn number_to_digits(mut x: u128, base: u8) -> Vec<u8> {
@@ -21,7 +21,7 @@ where I: Iterator<Item=u8> {
x.fold(0, |out, digit| out * base + digit as u128)
}
-pub fn digits_to_string<'a, I>(x: I, alphabet: &'a [u8]) -> String
+pub fn digits_to_string<I>(x: I, alphabet: &[u8]) -> String
where I: Iterator<Item=u8> {
x.map(|d| alphabet[d as usize] as char).collect()
}
diff --git a/src/main.rs b/src/main.rs
index 672ddde..790feb2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,9 +7,6 @@ use std::{
path::PathBuf
};
-use itertools;
-use rand;
-
use config::Config;
use structopt::StructOpt;
@@ -17,7 +14,6 @@ use mime_guess::{ Mime, MimeGuess };
use bytes::Bytes;
use futures::stream::{ self, StreamExt };
-use async_compat::Compat;
use rusoto_core::{
request,
Region, ByteStream,
@@ -31,7 +27,7 @@ use rusoto_s3::{
mod base62;
-const ONE_TRUE_THEME: &'static str = "Solarized (dark)";
+const ONE_TRUE_THEME: &str = "Solarized (dark)";
#[derive(StructOpt, Debug, Clone, Serialize, Deserialize)]
struct Opt {
@@ -75,7 +71,7 @@ fn main() {
let xdg = xdg::BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).unwrap();
let xdg_file = xdg.find_config_file("config.json");
let cfg_file = opt.config_file.clone()
- .or(env::var("PB_CONFIG_FILE").map(PathBuf::from).ok())
+ .or_else(|| env::var("PB_CONFIG_FILE").map(PathBuf::from).ok())
.or(xdg_file);
if let Some(cfg_file) = cfg_file {
let cfg_file = cfg_file.to_str().expect("Config file has invalid path");
@@ -91,7 +87,7 @@ fn main() {
cfg
};
- smol::block_on(Compat::new(async_main(cfg)));
+ smol::block_on(async_compat::Compat::new(async_main(cfg)));
}
async fn async_main(cfg: Config) {
@@ -99,7 +95,7 @@ async fn async_main(cfg: Config) {
endpoint: {
// trailing / causes problems with rusoto
let mut s = cfg.get_str("endpoint").expect("No endpoint set");
- if s.chars().last() == Some('/') { s.pop(); }
+ if s.ends_with('/') { s.pop(); }
s
},
name: cfg.get_str("region").expect("No region set")
@@ -134,8 +130,8 @@ async fn async_main(cfg: Config) {
.unwrap_or_else(|| {
let len = cfg.get_int("id_length").unwrap() as u32;
(0..).map(|_| random_id(len))
- .filter(|key| !smol::block_on(check_exists(&client, bucket.clone(), key.clone())))
- .next().unwrap()
+ .find(|key| !smol::block_on(check_exists(&client, bucket.clone(), key.clone())))
+ .unwrap()
});
let mime = if code { String::from("text/html; charset=utf-8") } else {
@@ -158,7 +154,7 @@ async fn async_main(cfg: Config) {
println!("{}", name);
}
-static TEMPLATE: &'static str = include_str!("./code.html");
+static TEMPLATE: &str = include_str!("./code.html");
#[derive(Serialize)]
struct Template { title: String, code: String }
fn highlight(cfg: &Config, mut input: Box<dyn BufRead + Send>) -> impl Iterator<Item=Bytes> {