Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Refactor HttpRequest and HttpResponse.
Browse files Browse the repository at this point in the history
This commit refactors HttpRequest and HttpResponse to directly store the data
rather than an inner `RpcHttp`.

It also implements support for cookies in `HttpRequest`, `HttpResponse`, and
`ResponseBuilder`.

Also enables more lints and fixes the clippy warnings.

Binding attributes for parameters have moved to the parameters in the examples
and documentation.

Fixes #346.
Fixes #281.
  • Loading branch information
peterhuene committed Nov 20, 2019
1 parent ed405f6 commit 07b7192
Show file tree
Hide file tree
Showing 114 changed files with 1,479 additions and 1,334 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
# Use nightly until rustfmt works for attributes on parameters
toolchain: nightly
default: true
components: rustfmt
- name: Run rustfmt
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use azure_functions::{
pub fn greet(req: HttpRequest) -> HttpResponse {
format!(
"Hello from Rust, {}!\n",
req.query_params().get("name").map_or("stranger", |x| x)
req.query_params.get("name").map_or("stranger", |x| x)
)
.into()
}
Expand All @@ -67,7 +67,7 @@ pub async fn greet_async(req: HttpRequest) -> HttpResponse {
// Use ready().await to simply demonstrate the async/await feature
ready(format!(
"Hello from Rust, {}!\n",
req.query_params().get("name").map_or("stranger", |x| x)
req.query_params.get("name").map_or("stranger", |x| x)
))
.await
.into()
Expand Down
4 changes: 2 additions & 2 deletions azure-functions-codegen/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Parse for PathVec {
fn parse(input: ParseStream) -> parse::Result<Self> {
let paths = Punctuated::<Path, Token![,]>::parse_terminated(input)?;

Ok(PathVec(paths.into_iter().collect()))
Ok(Self(paths.into_iter().collect()))
}
}

Expand All @@ -36,7 +36,7 @@ impl From<TokenStream> for PathVec {
return Self::default();
}

parse::<PathVec>(stream)
parse::<Self>(stream)
.map_err(|e| macro_panic(Span::call_site(), e.to_string()))
.unwrap()
}
Expand Down
3 changes: 3 additions & 0 deletions azure-functions-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//! This crate supports the code generation for the `azure-functions` crate.
#![recursion_limit = "128"]
#![deny(unused_extern_crates)]
#![warn(clippy::use_self)]
#![warn(clippy::option_map_unwrap_or)]
#![warn(clippy::option_map_unwrap_or_else)]
#![cfg_attr(feature = "unstable", feature(proc_macro_diagnostic))]
extern crate proc_macro;

Expand Down
4 changes: 4 additions & 0 deletions azure-functions-durable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! # Durable Functions HTTP client for Rust.
#![deny(missing_docs)]
#![deny(unused_extern_crates)]
#![warn(clippy::use_self)]
#![warn(clippy::option_map_unwrap_or)]
#![warn(clippy::option_map_unwrap_or_else)]

mod client;
mod endpoint;
Expand Down
3 changes: 3 additions & 0 deletions azure-functions-sdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
//! ```
#![deny(missing_docs)]
#![deny(unused_extern_crates)]
#![warn(clippy::use_self)]
#![warn(clippy::option_map_unwrap_or)]
#![warn(clippy::option_map_unwrap_or_else)]

mod commands;
mod util;
Expand Down
5 changes: 3 additions & 2 deletions azure-functions-sdk/src/templates/new/blob.rs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use azure_functions::{
};

#[func]
#[binding(name = "trigger", path = "{{path}}")]
pub fn {{name}}(trigger: BlobTrigger) {
pub fn {{name}}(
#[binding(path = "{{path}}")] trigger: BlobTrigger
) {
// trigger.path has the path to the blob that triggered the function
// trigger.blob has the contents of the blob
}
9 changes: 3 additions & 6 deletions azure-functions-sdk/src/templates/new/eventhub.rs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ use azure_functions::{
};

#[func]
{{#if hub_name~}}
#[binding(name = "trigger", connection = "{{connection}}", event_hub_name = "{{hub_name}}")]
{{else~}}
#[binding(name = "trigger", connection = "{{connection}}")]
{{/if~}}
pub fn {{name}}(trigger: EventHubTrigger) {
pub fn {{name}}(
#[binding(connection = "{{connection}}"{{#if hub_name}}, event_hub_name = "{{hub_name}}"{{/if}})] trigger: EventHubTrigger
) {
// trigger.message contains the message posted to the Event Hub
}
9 changes: 7 additions & 2 deletions azure-functions-sdk/src/templates/new/http.rs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use azure_functions::{

#[func]
{{#if auth_level~}}
#[binding(name = "req", auth_level = "{{auth_level}}")]
{{/if~}}
pub fn {{name}}(
#[binding(auth_level = "{{auth_level}}")] req: HttpRequest
) -> HttpResponse {
"Hello from Rust!".into()
}
{{else~}}
pub fn {{name}}(req: HttpRequest) -> HttpResponse {
"Hello from Rust!".into()
}
{{/if~}}
5 changes: 3 additions & 2 deletions azure-functions-sdk/src/templates/new/queue.rs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use azure_functions::{
};

#[func]
#[binding(name = "trigger", queue_name = "{{queue_name}}")]
pub fn {{name}}(trigger: QueueTrigger) {
pub fn {{name}}(
#[binding(queue_name = "{{queue_name}}")] trigger: QueueTrigger
) {
// trigger.message contains the message posted to the queue
}
9 changes: 3 additions & 6 deletions azure-functions-sdk/src/templates/new/servicebus.rs.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use azure_functions::{bindings::ServiceBusTrigger, func};

#[func]
{{#if queue~}}
#[binding(name = "trigger", connection = "{{connection}}", queue_name = "{{queue}}")]
{{else~}}
#[binding(name = "trigger", connection = "{{connection}}", topic_name = "{{topic}}", subscription_name = "{{subscription}}")]
{{/if~}}
pub fn {{name}}(trigger: ServiceBusTrigger) {
pub fn {{name}}(
#[binding(connection = "{{connection}}", {{#if queue}}queue_name = "{{queue}}"{{else}}topic_name = "{{topic}}", subscription_name = "{{subscription}}"{{/if}})] trigger: ServiceBusTrigger
) {
// trigger.message contains the posted message
}
5 changes: 3 additions & 2 deletions azure-functions-sdk/src/templates/new/timer.rs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use azure_functions::{
};

#[func]
#[binding(name = "trigger", schedule = "{{schedule}}")]
pub fn {{name}}(trigger: TimerInfo) {
pub fn {{name}}(
#[binding(schedule = "{{schedule}}")] trigger: TimerInfo
) {
// function will execute at the scheduled interval
}
22 changes: 11 additions & 11 deletions azure-functions-shared-codegen/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl From<AttributeArgs> for BindingArguments {
);
}

BindingArguments {
Self {
name: name.unwrap(),
direction,
validate,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl From<AttributeArgs> for FieldArguments {
true
});

FieldArguments {
Self {
name,
camel_case_value,
values,
Expand Down Expand Up @@ -160,14 +160,14 @@ impl From<&TypePath> for FieldType {
type_name.retain(|c| c != ' ');

match type_name.as_ref() {
"Cow<'static,str>" => FieldType::String,
"Option<Cow<'static,str>>" => FieldType::OptionalString,
"bool" => FieldType::Boolean,
"Option<bool>" => FieldType::OptionalBoolean,
"Direction" => FieldType::Direction,
"Cow<'static,[Cow<'static,str>]>" => FieldType::StringArray,
"i64" => FieldType::Integer,
"Option<i64>" => FieldType::OptionalInteger,
"Cow<'static,str>" => Self::String,
"Option<Cow<'static,str>>" => Self::OptionalString,
"bool" => Self::Boolean,
"Option<bool>" => Self::OptionalBoolean,
"Direction" => Self::Direction,
"Cow<'static,[Cow<'static,str>]>" => Self::StringArray,
"i64" => Self::Integer,
"Option<i64>" => Self::OptionalInteger,
_ => macro_panic(
tp.span(),
format!("field type '{}' is not supported for a binding", type_name),
Expand Down Expand Up @@ -374,7 +374,7 @@ impl From<&syn::Field> for Field {
args = Some(parse_attribute_args(&attr));
}

Field {
Self {
ident: field.ident.as_ref().unwrap().clone(),
args: args.map(Into::into),
ty: match &field.ty {
Expand Down
3 changes: 3 additions & 0 deletions azure-functions-shared-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//!
//! This crate supports code generation for the `azure-functions-shared` crate.
#![deny(unused_extern_crates)]
#![warn(clippy::use_self)]
#![warn(clippy::option_map_unwrap_or)]
#![warn(clippy::option_map_unwrap_or_else)]
#![recursion_limit = "128"]
#![cfg_attr(feature = "unstable", feature(proc_macro_diagnostic))]
extern crate proc_macro;
Expand Down
Loading

0 comments on commit 07b7192

Please sign in to comment.