Repository: rustless/rustless (language: rust)

Issue:
Followup: Does not compile with beta
From this issue: #38 

This should work before the 1.0 release to ensure it will work with 1.0 as well.



Discussion / hints:
To this end, I've updated `queryst` to build with beta with this PR: rustless/queryst#5.

I have begun work on `rustless/valico` but I have one issue remaining, dealing with `mopa`.

I've updated `rustless/valico` with PR rustless/valico#10 to work with beta

I've updated `mopa` with PR chris-morgan/mopa#2 so it works with beta. Depending on how well this PR is received, I might update the `valico` PR to use `mopa` once again.


Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 1012ee73..84a7e1fb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ iron_backend = ["iron", "bodyparser", "plugin"]
 
 [dependencies]
 regex = "*"
-regex_macros = "*"
+lazy_static = "*"
 rustc-serialize = "*"
 valico = "*"
 queryst = "*"
@@ -45,6 +45,3 @@ version = "*"
 [dependencies.plugin]
 optional = true
 version = "*"
-
-[dev-dependencies]
-dsl_macros = "*"
diff --git a/examples/simple.rs b/examples/simple.rs
index f37b4ec0..1eff3e94 100644
--- a/examples/simple.rs
+++ b/examples/simple.rs
@@ -1,7 +1,3 @@
-#![feature(plugin)]
-
-#![plugin(dsl_macros)]
-
 #[macro_use]
 extern crate rustless;
 
@@ -39,13 +35,13 @@ impl fmt::Display for UnauthorizedError {
 
 fn main() {
 
-    let mut app = rustless::Application::new(rustless::Api::build(dsl!(|api| {
-        prefix("api");
-        version("v1", rustless::Versioning::Path);
+    let mut app = rustless::Application::new(rustless::Api::build(|api| {
+        api.prefix("api");
+        api.version("v1", rustless::Versioning::Path);
 
-        mount(swagger::create_api("api-docs"));
+        api.mount(swagger::create_api("api-docs"));
 
-        error_formatter(|err, _media| {
+        api.error_formatter(|err, _media| {
             match err.downcast::<UnauthorizedError>() {
                 Some(_) => {
                     return Some(rustless::Response::from_string(
@@ -57,38 +53,38 @@ fn main() {
             }
         });
 
-        post("greet/:name", dsl!(|endpoint| {
-            summary("Sends greeting");
-            desc("Use this to talk to yourself");
-            params(|params| {
+        api.post("greet/:name", |endpoint| {
+            endpoint.summary("Sends greeting");
+            endpoint.desc("Use this to talk to yourself");
+            endpoint.params(|params| {
                 params.req_typed("name", json_dsl::string());
                 params.req_typed("greeting", json_dsl::string());
             });
-            handle(|client, params| {
+            endpoint.handle(|client, params| {
                 client.text(
                     format!("{}, {}",
                         params.find("greeting").unwrap().to_string(),
                         params.find("name").unwrap().to_string())
                 )
             })
-        }));
+        });
 
-        get("echo", dsl!(|endpoint| {
-            summary("Sends back what it gets");
-            desc("Use this to talk to yourself");
-            handle(|client, params| {
+        api.get("echo", |endpoint| {
+            endpoint.summary("Sends back what it gets");
+            endpoint.desc("Use this to talk to yourself");
+            endpoint.handle(|client, params| {
                 client.json(params)
             })
-        }));
+        });
 
-        namespace("admin", dsl!(|admin_ns| {
+        api.namespace("admin", |admin_ns| {
 
-            params(|params| {
+            admin_ns.params(|params| {
                 params.req_typed("token", json_dsl::string())
             });
 
             // Using after_validation callback to check token
-            after_validation(|_client, params| {
+            admin_ns.after_validation(|_client, params| {
 
                 match params.find("token") {
                     // We can unwrap() safely because token in validated already
@@ -105,10 +101,10 @@ fn main() {
             });
 
             // This `/api/admin/server_status` endpoint is secure now
-            get("server_status", dsl!(|endpoint| {
-                summary("Get server status");
-                desc("Use this API to receive some useful information about the state of our server");
-                handle(|client, _params| {
+            admin_ns.get("server_status", |endpoint| {
+                endpoint.summary("Get server status");
+                endpoint.desc("Use this API to receive some useful information about the state of our server");
+                endpoint.handle(|client, _params| {
                     {
                         let cookies = client.request.cookies();
                         let signed_cookies = cookies.signed();
@@ -119,9 +115,9 @@ fn main() {
 
                     client.text("Everything is OK".to_string())
                 })
-            }));
-        }))
-    })));
+            });
+        })
+    }));
 
     swagger::enable(&mut app, swagger::Spec {
         info: swagger::Info {
diff --git a/src/batteries/swagger.rs b/src/batteries/swagger.rs
index a6db5873..26cf1616 100644
--- a/src/batteries/swagger.rs
+++ b/src/batteries/swagger.rs
@@ -1,6 +1,6 @@
 use std::ascii::AsciiExt;
 use valico::json_dsl;
-use collections;
+use std::collections;
 use serialize::json::{self, ToJson};
 use jsonway::{self, MutableJson};
 use framework::{self, Nesting, ApiHandler};
@@ -460,7 +460,7 @@ fn fill_paths<'a>(mut context: WalkContext<'a>, paths: &mut jsonway::ObjectBuild
             path.push_str(&("/".to_string() + &encode_path_string(&namespace.path)));
 
             let mut params = context.params.clone();
-            params.append(&mut extract_params(&namespace.coercer, &namespace.path));
+            params.extend(extract_params(&namespace.coercer, &namespace.path));
 
             fill_paths(WalkContext{
                 path: &path,
diff --git a/src/framework/media.rs b/src/framework/media.rs
index d4cbab2e..baa394ea 100644
--- a/src/framework/media.rs
+++ b/src/framework/media.rs
@@ -2,7 +2,9 @@
 use regex;
 use server::mime;
 
-static MEDIA_REGEX: regex::Regex = regex!(r"vnd\.(?P<vendor>[a-zA-Z_-]+)(?:\.(?P<version>[a-zA-Z0-9]+)(?:\.(?P<param>[a-zA-Z0-9]+))?)?(?:\+(?P<format>[a-zA-Z0-9]+))?");
+lazy_static! {
+    static ref MEDIA_REGEX: regex::Regex = regex::Regex::new(r"vnd\.(?P<vendor>[a-zA-Z_-]+)(?:\.(?P<version>[a-zA-Z0-9]+)(?:\.(?P<param>[a-zA-Z0-9]+))?)?(?:\+(?P<format>[a-zA-Z0-9]+))?").unwrap();
+}
 
 pub fn is_json(mime: &mime::Mime) -> bool {
     match mime {
diff --git a/src/framework/mod.rs b/src/framework/mod.rs
index a21bfe2e..e0c50663 100644
--- a/src/framework/mod.rs
+++ b/src/framework/mod.rs
@@ -2,6 +2,7 @@ use serialize::json;
 
 use backend;
 use errors;
+use mopa;
 
 pub use self::app::{Application};
 pub use self::api::{Api, Versioning, Version};
@@ -28,7 +29,7 @@ pub struct CallInfo<'a> {
     pub app: &'a app::Application
 }
 
-pub trait ApiHandler: ::std::any::Any {
+pub trait ApiHandler : mopa::Any {
     fn api_call<'a, 'b>(&'a self, &str, &mut json::Json, &'b mut (backend::Request + 'b), &mut CallInfo<'a>) -> backend::HandleResult<backend::Response>;
 }
 
diff --git a/src/framework/path.rs b/src/framework/path.rs
index a92fe5af..15194dc9 100644
--- a/src/framework/path.rs
+++ b/src/framework/path.rs
@@ -2,7 +2,9 @@ use valico::MutableJson;
 use serialize::json::{self, ToJson};
 use regex;
 
-pub static MATCHER: regex::Regex = regex!(r":([a-z][a-z_]*)");
+lazy_static! {
+    pub static ref MATCHER: regex::Regex = regex::Regex::new(r":([a-z][a-z_]*)").unwrap();
+}
 
 pub struct Path {
     regex: regex::Regex,
diff --git a/src/lib.rs b/src/lib.rs
index e12a422d..4c256634 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,13 +1,8 @@
 #![crate_name = "rustless"]
 #![crate_type = "rlib"]
-#![feature(plugin)]
-#![feature(collections)]
-#![feature(core)]
 // #![deny(warnings)]
 #![deny(bad_style)]
 
-#![plugin(regex_macros)]
-
 extern crate regex;
 extern crate hyper;
 extern crate rustc_serialize as serialize;
@@ -20,15 +15,17 @@ extern crate typemap;
 extern crate plugin;
 extern crate bodyparser;
 
-extern crate collections;
 extern crate valico;
 extern crate queryst;
 extern crate jsonway;
 
+#[macro_use]
+extern crate lazy_static;
+
 #[macro_use]
 extern crate log;
 
-#[macro_use] #[no_link]
+#[macro_use]
 extern crate mopa;
 
 pub use backend::{Request, SimpleRequest, Response, Handler, HandleResult, HandleSuccessResult};


Test patch: