Run cargo fmt

This commit is contained in:
Jordan Johnson-Doyle 2019-02-15 22:01:22 +00:00
parent b32010f905
commit 09e411739a
No known key found for this signature in database
GPG key ID: A95F87B578CE79B6
4 changed files with 61 additions and 34 deletions

View file

@ -2,18 +2,22 @@ extern crate gpw;
extern crate linked_hash_map;
extern crate rand;
use rand::{Rng, thread_rng};
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use linked_hash_map::LinkedHashMap;
use std::sync::RwLock;
use std::env;
use std::cell::RefCell;
use std::env;
use std::sync::RwLock;
lazy_static! {
static ref ENTRIES: RwLock<LinkedHashMap<String, String>> = RwLock::new(LinkedHashMap::new());
static ref BUFFER_SIZE: usize = env::var("BIN_BUFFER_SIZE").map(|f| f.parse::<usize>().expect("Failed to parse value of BIN_BUFFER_SIZE")).unwrap_or(1000usize);
static ref BUFFER_SIZE: usize = env::var("BIN_BUFFER_SIZE")
.map(|f| f
.parse::<usize>()
.expect("Failed to parse value of BIN_BUFFER_SIZE"))
.unwrap_or(1000usize);
}
/// Ensures `ENTRIES` is less than the size of `BIN_BUFFER_SIZE`. If it isn't then
@ -37,18 +41,32 @@ fn purge_old() {
/// Generates a 'pronounceable' random ID using gpw
pub fn generate_id() -> String {
thread_local!(static KEYGEN: RefCell<gpw::PasswordGenerator> = RefCell::new(gpw::PasswordGenerator::default()));
KEYGEN.with(|k| k.borrow_mut().next().unwrap_or_else(|| thread_rng().sample_iter(&Alphanumeric).take(6).collect::<String>()))
KEYGEN.with(|k| {
k.borrow_mut().next().unwrap_or_else(|| {
thread_rng()
.sample_iter(&Alphanumeric)
.take(6)
.collect::<String>()
})
})
}
/// Stores a paste under the given id
pub fn store_paste(id: String, content: String) {
purge_old();
ENTRIES.write().unwrap_or_else(|p| p.into_inner()).insert(id, content);
ENTRIES
.write()
.unwrap_or_else(|p| p.into_inner())
.insert(id, content);
}
/// Get a paste by id.
///
/// Returns `None` if the paste doesn't exist.
pub fn get_paste(id: &str) -> Option<String> {
ENTRIES.read().unwrap_or_else(|p| p.into_inner()).get(id).cloned()
}
ENTRIES
.read()
.unwrap_or_else(|p| p.into_inner())
.get(id)
.cloned()
}