File tree Expand file tree Collapse file tree 4 files changed +68
-0
lines changed
Expand file tree Collapse file tree 4 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ This examples directory shows some examples written in Rust.
2+
3+ You can also test the command files by running from the command line.
Original file line number Diff line number Diff line change 1+ use std:: io:: { self , Write } ;
2+ use std:: { thread, time} ;
3+
4+ // Simple example script that counts to 10 at ~2Hz, then stops.
5+ fn main ( ) {
6+ for i in 1 ..11 {
7+ println ! ( "{}" , i) ;
8+ io:: stdout ( ) . flush ( ) . ok ( ) . expect ( "Could not flush stdout" ) ;
9+ thread:: sleep ( time:: Duration :: from_millis ( 500 ) ) ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ // Standard CGI(ish) environment variables, as defined in
2+ // http://tools.ietf.org/html/rfc3875
3+
4+ use std:: env;
5+
6+ const NAMES : & ' static [ & ' static str ] = & [
7+ "AUTH_TYPE" ,
8+ "CONTENT_LENGTH" ,
9+ "CONTENT_TYPE" ,
10+ "GATEWAY_INTERFACE" ,
11+ "PATH_INFO" ,
12+ "PATH_TRANSLATED" ,
13+ "QUERY_STRING" ,
14+ "REMOTE_ADDR" ,
15+ "REMOTE_HOST" ,
16+ "REMOTE_IDENT" ,
17+ "REMOTE_PORT" ,
18+ "REMOTE_USER" ,
19+ "REQUEST_METHOD" ,
20+ "REQUEST_URI" ,
21+ "SCRIPT_NAME" ,
22+ "SERVER_NAME" ,
23+ "SERVER_PORT" ,
24+ "SERVER_PROTOCOL" ,
25+ "SERVER_SOFTWARE" ,
26+ "UNIQUE_ID" ,
27+ "HTTPS" ,
28+ ] ;
29+
30+ fn main ( ) {
31+ for key in NAMES {
32+ let value = env:: var ( key) . unwrap_or ( String :: from ( "<unset>" ) ) ;
33+ println ! ( "{}={}" , key, value) ;
34+ }
35+ for ( key, value) in env:: vars ( ) {
36+ if key. starts_with ( "HTTP_" ) {
37+ println ! ( "{}={}" , key, value) ;
38+ }
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ use std:: io:: { self , Write } ;
2+
3+ // For each line FOO received on STDIN, respond with "Hello FOO!".
4+ fn main ( ) {
5+ loop {
6+ let mut msg = String :: new ( ) ;
7+ io:: stdin ( )
8+ . read_line ( & mut msg)
9+ . expect ( "Failed to read line" ) ;
10+ let msg = msg. trim ( ) ;
11+ println ! ( "Hello {}!" , msg) ;
12+ io:: stdout ( ) . flush ( ) . ok ( ) . expect ( "Could not flush stdout" ) ;
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments