Skip to content

Commit

Permalink
Add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
w4 committed Feb 12, 2019
1 parent 2c15718 commit 4fde268
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use syntect::html::{styled_line_to_highlighted_html, IncludeBackground};

/// Takes the content of a paste and the extension passed in by the viewer and will return the content
/// highlighted in the appropriate format in HTML.
///
/// Returns `None` if the extension isn't supported.
pub fn highlight(content: &str, ext: &str) -> Option<String> {
lazy_static! {
static ref SS: SyntaxSet = SyntaxSet::load_defaults_newlines();
Expand Down
8 changes: 7 additions & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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()
}
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(proc_macro_hygiene, decl_macro)]
#![feature(uniform_paths)]
#![feature(type_alias_enum_variants)]

#[macro_use] extern crate lazy_static;
Expand Down Expand Up @@ -28,6 +27,10 @@ use rocket::http::ContentType;

use std::io::Read;

///
/// Homepage
///

#[derive(Template)]
#[template(path = "index.html")]
struct Index {}
Expand All @@ -38,6 +41,10 @@ fn index() -> Index {
}


///
/// Submit Paste
///

#[derive(FromForm)]
struct IndexForm {
val: String
Expand All @@ -63,6 +70,10 @@ fn submit_raw(input: Data, host: HostHeader) -> std::io::Result<String> {
}


///
/// Show paste page
///

#[derive(Template)]
#[template(path = "paste.html")]
struct Render {
Expand Down

0 comments on commit 4fde268

Please sign in to comment.