From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

Added missing src directories to rust-example and rust-httpserver apps

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>

---
diff --git a/rust-example/src/lib.rs b/rust-example/src/lib.rs
--- a/rust-example/src/lib.rs
+++ b/rust-example/src/lib.rs
@@ -0,0 +1,11 @@
+extern crate rustc_version_runtime;
+use rustc_version_runtime::version;
+
+// This is the main function
+#[no_mangle]
+pub extern fn main() {
+ // The statements here will be executed when the compiled binary is called
+
+    // Print text to the console
+    println!("Hello World from Rust {:?} on OSv!", version());
+}
diff --git a/rust-httpserver/src/lib.rs b/rust-httpserver/src/lib.rs
--- a/rust-httpserver/src/lib.rs
+++ b/rust-httpserver/src/lib.rs
@@ -0,0 +1,44 @@
+// The code is based on the example found here -
+// https://hyper.rs/guides/server/hello-world/.
+//
+extern crate hyper;
+extern crate futures;
+
+use futures::future::Future;
+
+use hyper::header::ContentLength;
+use hyper::server::{Http, Request, Response, Service};
+
+struct HelloWorld;
+
+const PHRASE: &'static str = "Hello, World from Rust on OSv!";
+
+impl Service for HelloWorld {
+    // boilerplate hooking up hyper's server types
+    type Request = Request;
+    type Response = Response;
+    type Error = hyper::Error;
+    // The future representing the eventual Response your call will
+    // resolve to. This can change to whatever Future you need.
+    type Future = Box<Future<Item=Self::Response, Error=Self::Error>>;
+
+    fn call(&self, _req: Request) -> Self::Future {
+        // We're currently ignoring the Request
+        // And returning an 'ok' Future, which means it's ready
+        // immediately, and build a Response with the 'PHRASE' body.
+        Box::new(futures::future::ok(
+            Response::new()
+                .with_header(ContentLength(PHRASE.len() as u64))
+                .with_body(PHRASE)
+        ))
+    }
+}
+
+// This is the main function
+#[no_mangle]
+pub extern fn main() {
+    let addr = "0.0.0.0:3000".parse().unwrap();
+    let server = Http::new().bind(&addr, || Ok(HelloWorld)).unwrap();
+    println!("Starting http server to listen on port {} ...", 3000);
+    server.run().unwrap();
+}

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to