Upgrade to Tokio 1.x, futures 0.3, Hyper 0.14, etc (#459)

* Upgrade dependencies, oneshot channel ref

* New service style?

* Fix warning

* A server is running again

* Working server with async blocks

* UI working again

* Finish upgrade

* Bump MSRV to 1.46.0 for if/match in const fn

* Update the README as part of this
This commit is contained in:
Lucien Greathouse
2021-07-28 12:29:46 -04:00
committed by GitHub
parent 4aa5814a0a
commit 5d62bf9b60
10 changed files with 422 additions and 285 deletions

View File

@@ -1,23 +1,11 @@
use futures::{future, Future};
use hyper::{header::CONTENT_TYPE, Body, Response, StatusCode};
use serde::Serialize;
/// Respond to a request with JSON and the given status code.
pub fn json<T: Serialize>(
value: T,
code: StatusCode,
) -> Box<dyn Future<Item = hyper::Response<hyper::Body>, Error = hyper::Error> + Send> {
Box::new(future::ok(response_json(value, code)))
}
/// Respond to a request with a 200 OK response containing JSON.
pub fn json_ok<T: Serialize>(
value: T,
) -> Box<dyn Future<Item = hyper::Response<hyper::Body>, Error = hyper::Error> + Send> {
pub fn json_ok<T: Serialize>(value: T) -> Response<Body> {
json(value, StatusCode::OK)
}
fn response_json<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
pub fn json<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
let serialized = match serde_json::to_string(&value) {
Ok(v) => v,
Err(err) => {