Update doctests
This commit is contained in:
parent
eefb669e0d
commit
a3a247a5fe
|
@ -10,10 +10,9 @@ keywords = ["actix", "form-data", "multipart", "async"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-http = "2.0.0-alpha.3"
|
actix-multipart = "0.3.0"
|
||||||
actix-multipart = "0.3.0-alpha.1"
|
|
||||||
actix-rt = "1.1.1"
|
actix-rt = "1.1.1"
|
||||||
actix-web = "3.0.0-alpha.2"
|
actix-web = "3.0.1"
|
||||||
bytes = "0.5.0"
|
bytes = "0.5.0"
|
||||||
futures = "0.3.4"
|
futures = "0.3.4"
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
|
|
|
@ -51,10 +51,10 @@
|
||||||
//! .field(
|
//! .field(
|
||||||
//! "files",
|
//! "files",
|
||||||
//! Field::array(Field::file(|_, _, mut stream| async move {
|
//! Field::array(Field::file(|_, _, mut stream| async move {
|
||||||
//! while let Some(res) = stream.next().await {
|
//! while let Some(_) = stream.next().await {
|
||||||
//! res?;
|
//! // do something
|
||||||
//! }
|
//! }
|
||||||
//! Ok(()) as Result<(), Error>
|
//! Ok(None) as Result<_, std::convert::Infallible>
|
||||||
//! })),
|
//! })),
|
||||||
//! );
|
//! );
|
||||||
//!
|
//!
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
//! .wrap(form.clone())
|
//! .wrap(form.clone())
|
||||||
//! .service(resource("/upload").route(post().to(upload)))
|
//! .service(resource("/upload").route(post().to(upload)))
|
||||||
//! })
|
//! })
|
||||||
//! .bind("127.0.0.1:8080")?;
|
//! .bind("127.0.0.1:8082")?;
|
||||||
//! // commented out to prevent infinite doctest
|
//! // commented out to prevent infinite doctest
|
||||||
//! // .run()
|
//! // .run()
|
||||||
//! // .await?;
|
//! // .await?;
|
||||||
|
|
46
src/types.rs
46
src/types.rs
|
@ -20,7 +20,6 @@
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use tracing::trace;
|
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
|
@ -30,6 +29,7 @@ use std::{
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
use tracing::trace;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FileMeta {
|
pub struct FileMeta {
|
||||||
|
@ -45,7 +45,7 @@ pub struct FileMeta {
|
||||||
/// # Example usage
|
/// # Example usage
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::Value;
|
/// # use actix_form_data::Value;
|
||||||
/// # use std::collections::HashMap;
|
/// # use std::collections::HashMap;
|
||||||
/// # let mut hm = HashMap::new();
|
/// # let mut hm = HashMap::new();
|
||||||
/// # hm.insert("field-name".to_owned(), Value::Int(32));
|
/// # hm.insert("field-name".to_owned(), Value::Int(32));
|
||||||
|
@ -206,17 +206,23 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::{Form, Field};
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// # use tokio::sync::mpsc::channel;
|
/// # use tokio::sync::mpsc::channel;
|
||||||
|
/// # use futures::stream::StreamExt;
|
||||||
/// #
|
/// #
|
||||||
/// let (tx, rx) = channel(1);
|
/// let (tx, rx) = channel(1);
|
||||||
/// let form = Form::new().field("file-field", Field::file(|_, _, stream| async move {
|
/// let form = Form::new().field("file-field", Field::file(move |_, _, mut stream| {
|
||||||
/// while let Some(res) = stream.next().await {
|
/// let mut tx = tx.clone();
|
||||||
/// if let Err(_) = tx.send(res).await {
|
/// async move {
|
||||||
/// break;
|
/// while let Some(res) = stream.next().await {
|
||||||
|
/// if let Ok(bytes) = res {
|
||||||
|
/// if let Err(_) = tx.send(bytes).await {
|
||||||
|
/// break;
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
/// }
|
/// }
|
||||||
|
/// Ok(None) as Result<_, std::convert::Infallible>
|
||||||
/// }
|
/// }
|
||||||
/// Ok(()) as Result<(), std::convert::Infallible>
|
|
||||||
/// }));
|
/// }));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn file<F, Fut, E>(f: F) -> Self
|
pub fn file<F, Fut, E>(f: F) -> Self
|
||||||
|
@ -239,7 +245,7 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::{Form, Field};
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// let form = Form::new().field("text-field", Field::bytes());
|
/// let form = Form::new().field("text-field", Field::bytes());
|
||||||
pub fn bytes() -> Self {
|
pub fn bytes() -> Self {
|
||||||
Field::Bytes
|
Field::Bytes
|
||||||
|
@ -249,7 +255,7 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::{Form, Field};
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// let form = Form::new().field("text-field", Field::text());
|
/// let form = Form::new().field("text-field", Field::text());
|
||||||
pub fn text() -> Self {
|
pub fn text() -> Self {
|
||||||
Field::Text
|
Field::Text
|
||||||
|
@ -259,7 +265,7 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::{Form, Field};
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// let form = Form::new().field("int-field", Field::int());
|
/// let form = Form::new().field("int-field", Field::int());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn int() -> Self {
|
pub fn int() -> Self {
|
||||||
|
@ -270,7 +276,7 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::{Form, Field};
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// let form = Form::new().field("float-field", Field::float());
|
/// let form = Form::new().field("float-field", Field::float());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn float() -> Self {
|
pub fn float() -> Self {
|
||||||
|
@ -281,8 +287,7 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate form_data;
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// # use form_data::{Form, Field};
|
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// let form = Form::new()
|
/// let form = Form::new()
|
||||||
/// .field(
|
/// .field(
|
||||||
|
@ -299,8 +304,7 @@ impl Field {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate form_data;
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// # use form_data::{Form, Field};
|
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// let form = Form::new()
|
/// let form = Form::new()
|
||||||
/// .field(
|
/// .field(
|
||||||
|
@ -402,7 +406,7 @@ impl Map {
|
||||||
/// Add a `Field` to a map
|
/// Add a `Field` to a map
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::Field;
|
/// # use actix_form_data::Field;
|
||||||
/// #
|
/// #
|
||||||
/// Field::map()
|
/// Field::map()
|
||||||
/// .field("sub-field", Field::text())
|
/// .field("sub-field", Field::text())
|
||||||
|
@ -417,7 +421,7 @@ impl Map {
|
||||||
|
|
||||||
/// Finalize the map into a `Field`, so it can be added to a Form
|
/// Finalize the map into a `Field`, so it can be added to a Form
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::Field;
|
/// # use actix_form_data::Field;
|
||||||
/// #
|
/// #
|
||||||
/// Field::map()
|
/// Field::map()
|
||||||
/// .field("sub-field", Field::text())
|
/// .field("sub-field", Field::text())
|
||||||
|
@ -448,12 +452,14 @@ impl Map {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use form_data::{Form, Field};
|
/// # use actix_form_data::{Form, Field};
|
||||||
/// let form = Form::new()
|
/// let form = Form::new()
|
||||||
/// .field("field-name", Field::text())
|
/// .field("field-name", Field::text())
|
||||||
/// .field("second-field", Field::int())
|
/// .field("second-field", Field::int())
|
||||||
/// .field("third-field", Field::float())
|
/// .field("third-field", Field::float())
|
||||||
/// .field("fifth-field", Field::file())
|
/// .field("fifth-field", Field::file(|_, _, _| async move {
|
||||||
|
/// Ok(None) as Result<_, std::convert::Infallible>
|
||||||
|
/// }))
|
||||||
/// .field(
|
/// .field(
|
||||||
/// "map-field",
|
/// "map-field",
|
||||||
/// Field::map()
|
/// Field::map()
|
||||||
|
|
Loading…
Reference in a new issue