-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,262 additions
and
91 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
{ | ||
"version": "2.0.0", | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
}, | ||
"tasks": [ | ||
{ | ||
"taskName": "cargo build", | ||
"type": "shell", | ||
"command": "cargo", | ||
"args": [ | ||
"build" | ||
], | ||
"group": "build", | ||
"problemMatcher": "$rustc" | ||
}, | ||
{ | ||
"taskName": "run hello", | ||
"type": "shell", | ||
"command": "cargo", | ||
"args": [ | ||
"run", | ||
"--example", | ||
"hello" | ||
], | ||
"problemMatcher": "$rustc" | ||
}, | ||
{ | ||
"taskName": "run messages", | ||
"type": "shell", | ||
"command": "cargo", | ||
"args": [ | ||
"run", | ||
"--example", | ||
"messages" | ||
], | ||
"problemMatcher": "$rustc" | ||
}, | ||
{ | ||
"taskName": "cargo test", | ||
"type": "shell", | ||
"command": "cargo", | ||
"args": [ | ||
"test" | ||
], | ||
"group": "test", | ||
"problemMatcher": "$rustc" | ||
}, | ||
{ | ||
"taskName": "cargo clean", | ||
"type": "shell", | ||
"command": "cargo", | ||
"args": [ | ||
"clean" | ||
] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
[package] | ||
name = "tide" | ||
version = "0.0.0" | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/yoshuawuyts/tide" | ||
documentation = "https://docs.rs/tide" | ||
authors = [ | ||
"Aaron Turon <[email protected]>", | ||
"Yoshua Wuyts <[email protected]>", | ||
] | ||
description = "WIP modular web framework" | ||
authors = ["Yoshua Wuyts <[email protected]>"] | ||
documentation = "https://docs.rs/tide" | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
name = "tide" | ||
readme = "README.md" | ||
repository = "https://github.com/yoshuawuyts/tide" | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
http = "0.1" | ||
hyper = "0.12.0" | ||
pin-utils = "0.1.0-alpha.3" | ||
serde = "1.0.80" | ||
serde_derive = "1.0.80" | ||
serde_json = "1.0.32" | ||
typemap = "0.3.3" | ||
|
||
[dependencies.futures-preview] | ||
features = ["compat"] | ||
version = "0.3.0-alpha.9" | ||
|
||
[dev-dependencies] |
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 |
---|---|---|
@@ -1,29 +1,17 @@ | ||
# tide | ||
[![crates.io version][1]][2] [![build status][3]][4] | ||
[![downloads][5]][6] [![docs.rs docs][7]][8] | ||
# Tide | ||
|
||
WIP modular web framework. | ||
[![build status][1]][2] | ||
|
||
- [Documentation][8] | ||
- [Crates.io][2] | ||
An early, experimental web framework. **NOT PRODUCTION-READY**. | ||
|
||
## Usage | ||
```txt | ||
``` | ||
Read about the design here: | ||
|
||
## Installation | ||
```sh | ||
$ cargo add tide | ||
``` | ||
- [Rising Tide: building a modular web framework in the open](https://rust-lang-nursery.github.io/wg-net/2018/09/11/tide.html) | ||
- [Routing and extraction in Tide: a first sketch](https://rust-lang-nursery.github.io/wg-net/2018/10/16/tide-routing.html) | ||
|
||
## License | ||
|
||
[MIT](./LICENSE-MIT) OR [Apache-2.0](./LICENSE-APACHE) | ||
|
||
[1]: https://img.shields.io/crates/v/tide.svg?style=flat-square | ||
[2]: https://crates.io/crates/tide | ||
[3]: https://img.shields.io/travis/yoshuawuyts/tide.svg?style=flat-square | ||
[4]: https://travis-ci.org/yoshuawuyts/tide | ||
[5]: https://img.shields.io/crates/d/tide.svg?style=flat-square | ||
[6]: https://crates.io/crates/tide | ||
[7]: https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square | ||
[8]: https://docs.rs/tide | ||
[1]: https://img.shields.io/travis/yoshuawuyts/tide.svg?style=flat-square | ||
[2]: https://travis-ci.org/yoshuawuyts/tide |
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,7 @@ | ||
#![feature(async_await)] | ||
|
||
fn main() { | ||
let mut app = tide::App::new(()); | ||
app.at("/").get(async || "Hello, world!"); | ||
app.serve("127.0.0.1:7878") | ||
} |
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,85 @@ | ||
#![feature(async_await, futures_api)] | ||
|
||
#[macro_use] | ||
extern crate serde_derive; | ||
|
||
use http::status::StatusCode; | ||
use std::sync::{Arc, Mutex}; | ||
use tide::{body, head, App, AppData}; | ||
|
||
#[derive(Clone)] | ||
struct Database { | ||
contents: Arc<Mutex<Vec<Message>>>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
struct Message { | ||
author: Option<String>, | ||
contents: String, | ||
} | ||
|
||
impl Database { | ||
fn new() -> Database { | ||
Database { | ||
contents: Arc::new(Mutex::new(Vec::new())), | ||
} | ||
} | ||
|
||
fn insert(&mut self, msg: Message) -> usize { | ||
let mut table = self.contents.lock().unwrap(); | ||
table.push(msg); | ||
table.len() - 1 | ||
} | ||
|
||
fn get(&mut self, id: usize) -> Option<Message> { | ||
self.contents.lock().unwrap().get(id).cloned() | ||
} | ||
|
||
fn set(&mut self, id: usize, msg: Message) -> bool { | ||
let mut table = self.contents.lock().unwrap(); | ||
|
||
if let Some(old_msg) = table.get_mut(id) { | ||
*old_msg = msg; | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} | ||
|
||
async fn new_message(mut db: AppData<Database>, msg: body::Json<Message>) -> String { | ||
db.insert(msg.0).to_string() | ||
} | ||
|
||
async fn set_message( | ||
mut db: AppData<Database>, | ||
id: head::Path<usize>, | ||
msg: body::Json<Message>, | ||
) -> Result<(), StatusCode> { | ||
if db.set(id.0, msg.0) { | ||
Ok(()) | ||
} else { | ||
Err(StatusCode::NOT_FOUND) | ||
} | ||
} | ||
|
||
async fn get_message( | ||
mut db: AppData<Database>, | ||
id: head::Path<usize>, | ||
) -> Result<body::Json<Message>, StatusCode> { | ||
if let Some(msg) = db.get(id.0) { | ||
Ok(body::Json(msg)) | ||
} else { | ||
Err(StatusCode::NOT_FOUND) | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut app = App::new(Database::new()); | ||
|
||
app.at("/message").post(new_message); | ||
app.at("/message/{}").get(get_message); | ||
app.at("/message/{}").post(set_message); | ||
|
||
app.serve("127.0.0.1:7878"); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.