Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #25 from softprops/exp-mashup-macro
Browse files Browse the repository at this point in the history
(experimental) byo cratename
  • Loading branch information
softprops committed Oct 19, 2018
2 parents 5485a08 + 7c7345f commit 0c0ad2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.5"
mashup = "0.1"

[features]
default = ["cpython/python3-sys"]
60 changes: 18 additions & 42 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ extern crate failure;
extern crate failure_derive;
// re-export for convenience
pub extern crate http;
#[doc(hidden)]
pub extern crate mashup;
#[doc(hidden)]
pub use mashup::*;
extern crate serde;
#[macro_use]
extern crate serde_derive;
Expand Down Expand Up @@ -187,18 +191,18 @@ where
/// # }
/// ```
///
/// You can also the provide `gateway!` macro with a named function
/// You can also the provide `gateway!` macro with a function reference
///
/// The request argument is just a regular `http::Request` type
/// The `request` argument is just a regular `http::Request` type,
/// extendable with API gateway features, like accessing path and query string parameters, and
/// more by importing [lando::RequestExt`](trait.RequestExt.html)
///
/// The context argument is [same type](struct.LambdaContext.html) defined within the crowbar crate
/// The context argument is [same type](struct.LambdaContext.html) defined within the crowbar crate.
///
/// ```rust
/// # #[macro_use] extern crate lando;
/// # fn main() {
/// use lando::{LambdaContext, Request, Response, Result, Body};
/// use lando::{LambdaContext, Request, Response, Result};
///
/// fn handler(request: Request, context: LambdaContext) -> Result {
/// println!("{:?}", request);
Expand All @@ -209,7 +213,7 @@ where
/// # }
/// ```
///
/// # Multiple functions
/// # Export multiple lambda functions in one library
///
/// You can export multiple functions in the same module with a format similar to a `match` expression:
///
Expand All @@ -225,39 +229,6 @@ where
/// # }
/// ```
///
/// # Changing the dynamic library name
///
/// Be default, lando assumes a library named "lambda", If you need to change the
/// name of the resulting dynamic library that gets built,
/// you first need to change the `[lib]` section in your Cargo.toml file
///
/// ```toml
/// [lib]
/// name = "solo"
/// crate-type = ["cdylib"]
/// ```
///
/// You then also need to change the names of the library identifiers, expected by
/// the [cpython crate](https://dgrunwald.github.io/rust-cpython/doc/cpython/macro.py_module_initializer.html),
/// by using the following `gateway!` format. This pattern may no longer needed
/// the std library's [concat_idents!](https://doc.rust-lang.org/std/macro.concat_idents.html)
/// macro is stablized.
///
/// ```rust
/// # #[macro_use] extern crate lando;
/// # fn main() {
/// gateway! {
/// crate (libsolo, initlibsolo, PyInit_libsolo) {
/// "handler" => |request, context| {
/// Ok(lando::Response::new(
/// "hello from libsolo"
/// ))
/// }
/// }
/// };
/// # }
///
/// ```
#[macro_export]
macro_rules! gateway {
(@module ($module:ident, $py2:ident, $py3:ident)
Expand Down Expand Up @@ -291,11 +262,16 @@ macro_rules! gateway {
// dynamic
// see also https://www.ncameron.org/blog/untitledconcat_idents-and-macros-in-ident-position/
// https://github.com/rust-lang/rust/issues/29599
gateway! { @module (liblambda,
initliblambda,
PyInit_liblambda)
mashup! {
m["modulename"] = lib env!("CARGO_PKG_NAME");
m["py2_init"] = initlib env!("CARGO_PKG_NAME");
m["py3_init"] = PyInit_lib env!("CARGO_PKG_NAME");
}
m! {
gateway! { @module ("modulename", "py2_init", "py3_init")
@handlers ($($handler => $target),*) }
};
}
};
($($handler:expr => $target:expr,)*) => {
gateway! { $($handler => $target),* }
};
Expand Down

0 comments on commit 0c0ad2a

Please sign in to comment.