Code docs

This commit is contained in:
Lucien Greathouse
2021-06-11 22:19:50 -04:00
parent e482d038c6
commit 17fdd18c55
12 changed files with 72 additions and 37 deletions

View File

@@ -1,3 +1,7 @@
//! A simple asset reloading system intended for iterating on CSS. When in the
//! `dev_live_assets` feature is enabled, files are read from disk and watched
//! for changes. Otherwise, they're baked into the executable.
macro_rules! declare_asset {
($name: ident, $path: expr) => {
pub fn $name() -> &'static str {

View File

@@ -1,4 +1,6 @@
//! Defines all the structs needed to interact with the Rojo Serve API.
//! Defines all the structs needed to interact with the Rojo Serve API. This is
//! useful for tests to be able to use the same data structures as the
//! implementation.
use std::{
borrow::Cow,

View File

@@ -1,3 +1,7 @@
//! Defines the Rojo web interface. This is what the Roblox Studio plugin
//! communicates with. Eventually, we'll make this API stable, produce better
//! documentation for it, and open it up for other consumers.
mod api;
mod assets;
pub mod interface;

View File

@@ -1,4 +1,8 @@
//! Defines the HTTP-based UI. These endpoints generally return HTML and SVG.
//! Defines the HTTP-based Rojo UI. It uses ritz for templating, which is like
//! JSX for Rust. Eventually we should probably replace this with a new
//! framework, maybe using JS and client side rendering.
//!
//! These endpoints generally return HTML and SVG.
use std::{borrow::Cow, sync::Arc, time::Duration};

View File

@@ -2,6 +2,21 @@ 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> {
json(value, StatusCode::OK)
}
fn response_json<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
let serialized = match serde_json::to_string(&value) {
Ok(v) => v,
@@ -20,16 +35,3 @@ fn response_json<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
.body(Body::from(serialized))
.unwrap()
}
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)))
}
pub fn json_ok<T: Serialize>(
value: T,
) -> Box<dyn Future<Item = hyper::Response<hyper::Body>, Error = hyper::Error> + Send> {
json(value, StatusCode::OK)
}