~jplatte/turbo.fish

b2a0125acf2f062e97e66f1ac7f91555c645270a — Jonas Platte 1 year, 10 months ago 1d66cd6
Update to rocket 0.4, rand 0.7
4 files changed, 32 insertions(+), 17 deletions(-)

M Cargo.toml
M src/main.rs
M src/random.rs
M src/turbofish.rs
M Cargo.toml => Cargo.toml +3 -4
@@ 7,10 7,9 @@ version = "0.1.0"
edition = "2018"

[dependencies]
rand = "0.5.5"
rocket = "0.3.17"
rocket_codegen = "0.3.17"
rand = "0.7.0"
rocket = "0.4.2"

[dependencies.rocket_contrib]
version = "0.3.17"
version = "0.4.2"
features = ["tera_templates"]

M src/main.rs => src/main.rs +5 -10
@@ 1,5 1,4 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]

mod random;
mod turbofish;


@@ 10,10 9,11 @@ use std::{
};

use rocket::{
    http::uri::URI,
    get,
    response::{NamedFile, Redirect},
    routes, uri,
};
use rocket_contrib::Template;
use rocket_contrib::templates::Template;

use self::{random::random_type, turbofish::TurboFish};



@@ 27,12 27,7 @@ fn index() -> Template {

#[get("/random")]
fn random() -> Redirect {
    // Safari doesn't seem to like redirect URLs starting with ::
    // the leading / is here to fix that.
    Redirect::to(&format!(
        "/{}",
        URI::percent_encode(&format!("::<{}>", random_type()))
    ))
    Redirect::to(uri!(turbofish: TurboFish::new(random_type())))
}

#[get("/<turbofish>")]

M src/random.rs => src/random.rs +2 -2
@@ 1,4 1,4 @@
use rand::{self, Rng};
use rand::seq::SliceRandom;

const RECURSION_LIMIT: u8 = 1;



@@ 33,7 33,7 @@ pub fn random_type() -> String {
}

fn random_type_depth(depth: u8) -> String {
    let (type_name, generics) = rand::thread_rng().choose(TYPES).unwrap();
    let (type_name, generics) = TYPES.choose(&mut rand::thread_rng()).unwrap();
    if *generics == 0 {
        type_name.to_string()
    } else if depth == RECURSION_LIMIT {

M src/turbofish.rs => src/turbofish.rs +22 -1
@@ 1,8 1,21 @@
use rocket::{http::RawStr, request::FromParam};
use std::fmt;

use rocket::{
    http::{
        impl_from_uri_param_identity,
        uri::{Formatter, Path, UriDisplay},
        RawStr,
    },
    request::FromParam,
};

pub struct TurboFish(String);

impl TurboFish {
    pub fn new(guts: String) -> TurboFish {
        TurboFish(guts)
    }

    pub fn gut(self) -> String {
        self.0
    }


@@ 23,3 36,11 @@ impl<'a> FromParam<'a> for TurboFish {
        }
    }
}

impl UriDisplay<Path> for TurboFish {
    fn fmt(&self, f: &mut Formatter<Path>) -> fmt::Result {
        f.write_value(&format!("::<{}>", self.0))
    }
}

impl_from_uri_param_identity!([Path] TurboFish);