-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from tonytonyjan/patch-1
Rust examples
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This examples directory shows some examples written in Rust. | ||
|
||
You can also test the command files by running from the command line. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use std::io::{self, Write}; | ||
use std::{thread, time}; | ||
|
||
// Simple example script that counts to 10 at ~2Hz, then stops. | ||
fn main() { | ||
for i in 1..11 { | ||
println!("{}", i); | ||
io::stdout().flush().ok().expect("Could not flush stdout"); | ||
thread::sleep(time::Duration::from_millis(500)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Standard CGI(ish) environment variables, as defined in | ||
// http://tools.ietf.org/html/rfc3875 | ||
|
||
use std::env; | ||
|
||
const NAMES: &'static [&'static str] = &[ | ||
"AUTH_TYPE", | ||
"CONTENT_LENGTH", | ||
"CONTENT_TYPE", | ||
"GATEWAY_INTERFACE", | ||
"PATH_INFO", | ||
"PATH_TRANSLATED", | ||
"QUERY_STRING", | ||
"REMOTE_ADDR", | ||
"REMOTE_HOST", | ||
"REMOTE_IDENT", | ||
"REMOTE_PORT", | ||
"REMOTE_USER", | ||
"REQUEST_METHOD", | ||
"REQUEST_URI", | ||
"SCRIPT_NAME", | ||
"SERVER_NAME", | ||
"SERVER_PORT", | ||
"SERVER_PROTOCOL", | ||
"SERVER_SOFTWARE", | ||
"UNIQUE_ID", | ||
"HTTPS", | ||
]; | ||
|
||
fn main() { | ||
for key in NAMES { | ||
let value = env::var(key).unwrap_or(String::from("<unset>")); | ||
println!("{}={}", key, value); | ||
} | ||
for (key, value) in env::vars() { | ||
if key.starts_with("HTTP_") { | ||
println!("{}={}", key, value); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use std::io::{self, Write}; | ||
|
||
// For each line FOO received on STDIN, respond with "Hello FOO!". | ||
fn main() { | ||
loop { | ||
let mut msg = String::new(); | ||
io::stdin() | ||
.read_line(&mut msg) | ||
.expect("Failed to read line"); | ||
let msg = msg.trim(); | ||
println!("Hello {}!", msg); | ||
io::stdout().flush().ok().expect("Could not flush stdout"); | ||
} | ||
} |