This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
btn_load_file.connect_clicked( move | widget | { | |
// … | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
btn_load_file.connect_clicked( clone!( | |
lines, window => move | widget | { | |
// .. | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Calculats the length of the common pfix of two slices. | |
The slices a and b are zipped, leading to an iterator containing a tuple with a component of each of the input iterators | |
The iterators take care of handling different-sized slices (also slices of zero size) | |
*/ | |
fn common_prefix_len(a: &str, b: &str) -> usize { | |
a.chars().zip( | |
b.chars() | |
).take_while( | |
|(x, y)| x == y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parameter declarations can be clumy at times | |
pub fn handle_motion( | |
evt: &EventMotion, | |
fixed_container: &Fixed, | |
lines: RefMut<Vec<TextArea>>, | |
background_dimensions: RefMut<(u32, u32)>, | |
text_idx: RefMut<i32>, | |
){ | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the internal function that is not exposed otherwise | |
fn generate_preview(image: &RgbaImage) -> RgbaImage { | |
// ... | |
} | |
// ... | |
#[cfg(test)] // this ensures that this module is only included if you build a `test` target | |
mod tests { // the tests live in their own module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// creates a mpsc-channel for thread communication. | |
// the type of the channel is inferred at compile-time | |
let (tx, rx) = mpsc::channel(); | |
// (not shown) make the transmitter available to the other thread(s) | |
// ... | |
// start a new thread and capture the environment | |
thread::spawn(move || { | |
let mut lines = Vec::new(); | |
// .. other variables omitted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies.rocket] | |
version = "0.4.2" | |
features = ["private-cookies"] | |
[dependencies.rocket_contrib] | |
default-features = false | |
features = ["json","diesel_postgres_pool","serve"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[get("/health")] | |
fn health() -> &'static str { | |
"ok" | |
} | |
fn main() { | |
rocket::ignite() | |
.mount("/", routes![health]) | |
.launch(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate rocket; | |
#[get("/hello/<name>")] | |
fn hello(name: String) -> String { | |
format!("hello {}", name) | |
} | |
fn main() { | |
rocket::ignite() |
OlderNewer