فهرست منبع

Merge pull request #1636 from steveklabnik/rust

Add Rust
Mike Smith 10 سال پیش
والد
کامیت
1a23d854b3

+ 1 - 0
.travis.yml

@@ -156,6 +156,7 @@ env:
     - "TESTDIR=Ruby/sinatra"
     - "TESTDIR=Rust/iron"
     - "TESTDIR=Rust/nickel"
+    - "TESTDIR=Rust/hyper"
     - "TESTDIR=Scala/akka-http"
     - "TESTDIR=Scala/colossus"
     - "TESTDIR=Scala/finagle"

+ 8 - 0
frameworks/Rust/hyper/Cargo.toml

@@ -0,0 +1,8 @@
+[package]
+name = "hello"
+version = "0.1.0"
+authors = ["Steve Klabnik <[email protected]>"]
+
+[dependencies]
+
+hyper="0.5.2"

+ 22 - 0
frameworks/Rust/hyper/benchmark_config.json

@@ -0,0 +1,22 @@
+{
+  "framework": "hyper",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "plaintext_url": "/plaintext", 
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "Postgres",
+      "framework": "hyper",
+      "language": "Rust",
+      "orm": "Raw",
+      "platform": "Rust",
+      "webserver": "Hyper",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Hyper",
+      "notes": ""
+    }
+  }]
+}

+ 3 - 0
frameworks/Rust/hyper/install.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+fw_depends rust

+ 7 - 0
frameworks/Rust/hyper/setup.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+source $IROOT/rust.installed
+
+cargo clean
+cargo build --release
+cargo run --release &

+ 24 - 0
frameworks/Rust/hyper/src/main.rs

@@ -0,0 +1,24 @@
+extern crate hyper;
+
+use hyper::server::{Server, Request, Response};
+use hyper::status::StatusCode;
+use hyper::uri::RequestUri;
+use hyper::header::ContentType;
+use hyper::header::ContentLength;
+use hyper::header;
+
+const HELLO_WORLD: &'static [u8; 14] = b"Hello, World!\n";
+
+fn main() {
+    Server::http(|req: Request, mut res: Response| {
+        match (req.method, req.uri) {
+            (hyper::Get, RequestUri::AbsolutePath(ref path)) if path == "/plaintext" => {
+                res.headers_mut().set(ContentType::plaintext());
+                res.headers_mut().set(header::Server("Hyper".to_owned()));
+
+                res.send(HELLO_WORLD).unwrap();
+            }
+            _ => (),
+        };
+    }).listen("0.0.0.0:8080").unwrap();
+}

+ 1 - 0
source_code

@@ -0,0 +1 @@
+./src/main.rs