Add more comments

This commit is contained in:
Jordan Johnson-Doyle 2019-02-12 01:23:06 +00:00
parent 2c1571881e
commit 4fde268117
No known key found for this signature in database
GPG key ID: A95F87B578CE79B6
3 changed files with 21 additions and 2 deletions

View file

@ -13,6 +13,8 @@ lazy_static! {
/// Ensures `ENTRIES` is less than the size of `BIN_BUFFER_SIZE`. If it isn't then
/// `ENTRIES.len() - BIN_BUFFER_SIZE` elements will be popped off the front of the map.
///
/// During the purge, `ENTRIES` is locked and the current thread will block.
fn purge_old() {
let entries_len = ENTRIES.read().unwrap().len();
let buffer_size = env::var("BIN_BUFFER_SIZE").map(|f| f.parse::<usize>().unwrap()).unwrap_or(1000usize);
@ -29,6 +31,8 @@ fn purge_old() {
}
/// Generates a randomly generated id, stores the given paste under that id and then returns the id.
///
/// Uses gpw to generate a (most likely) pronounceable URL.
pub fn store_paste(content: String) -> String {
thread_local!(static KEYGEN: RefCell<gpw::PasswordGenerator> = RefCell::new(gpw::PasswordGenerator::default()));
let id = KEYGEN.with(|k| k.borrow_mut().next().unwrap());
@ -39,7 +43,9 @@ pub fn store_paste(content: String) -> String {
id
}
/// Get a paste by id. Returns `None` if the paste doesn't exist.
/// Get a paste by id.
///
/// Returns `None` if the paste doesn't exist.
pub fn get_paste(id: &str) -> Option<String> {
ENTRIES.read().unwrap().get(id).cloned()
}