pub struct GenericInput {
pub data: Value,
}
Expand description
Represents a generic input binding.
The following binding attributes are supported:
Name | Description |
---|---|
type | The binding type. |
name | The name of the parameter being bound. |
* | The additional binding attributes specific to the binding type. Supported value types are strings, booleans, and integers. |
§Examples
An example of using a GenericInput
binding instead of a CosmosDbDocument
binding:
use azure_functions::{
bindings::{GenericInput, HttpRequest, HttpResponse},
func,
generic::Value,
};
use serde_json::from_str;
#[func]
#[binding(name = "req", route = "read/{id}")]
#[binding(
type = "cosmosDB",
name = "document",
connectionStringSetting = "connection",
databaseName = "exampledb",
collectionName = "documents",
id = "{id}",
partitionKey = "{id}"
)]
pub fn read_document(req: HttpRequest, document: GenericInput) -> HttpResponse {
match document.data {
Value::String(s) => {
let v: serde_json::Value = from_str(&s).expect("expected JSON data");
if v.is_null() {
format!(
"Document with id '{}' does not exist.",
req.route_params().get("id").unwrap()
)
.into()
} else {
v.into()
}
}
_ => panic!("expected string for CosmosDB document data"),
}
}
Fields§
§data: Value
The input binding data.
Trait Implementations§
Source§impl Clone for GenericInput
impl Clone for GenericInput
Source§fn clone(&self) -> GenericInput
fn clone(&self) -> GenericInput
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for GenericInput
impl Debug for GenericInput
Auto Trait Implementations§
impl Freeze for GenericInput
impl RefUnwindSafe for GenericInput
impl Send for GenericInput
impl Sync for GenericInput
impl Unpin for GenericInput
impl UnwindSafe for GenericInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request