From a3a247a5fee4b9cc3bf460f0df0271b92ed4bf63 Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 13 Sep 2020 20:12:43 -0500 Subject: [PATCH] Update doctests --- Cargo.toml | 5 ++--- src/lib.rs | 8 ++++---- src/types.rs | 46 ++++++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68ed0c1..92ff1bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,9 @@ keywords = ["actix", "form-data", "multipart", "async"] edition = "2018" [dependencies] -actix-http = "2.0.0-alpha.3" -actix-multipart = "0.3.0-alpha.1" +actix-multipart = "0.3.0" actix-rt = "1.1.1" -actix-web = "3.0.0-alpha.2" +actix-web = "3.0.1" bytes = "0.5.0" futures = "0.3.4" mime = "0.3.16" diff --git a/src/lib.rs b/src/lib.rs index eaea46e..86e36f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,10 +51,10 @@ //! .field( //! "files", //! Field::array(Field::file(|_, _, mut stream| async move { -//! while let Some(res) = stream.next().await { -//! res?; +//! while let Some(_) = stream.next().await { +//! // do something //! } -//! Ok(()) as Result<(), Error> +//! Ok(None) as Result<_, std::convert::Infallible> //! })), //! ); //! @@ -65,7 +65,7 @@ //! .wrap(form.clone()) //! .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 //! // .run() //! // .await?; diff --git a/src/types.rs b/src/types.rs index 5a1235f..acfb1c9 100644 --- a/src/types.rs +++ b/src/types.rs @@ -20,7 +20,6 @@ use crate::Error; use bytes::Bytes; use futures::Stream; -use tracing::trace; use mime::Mime; use std::{ collections::{HashMap, VecDeque}, @@ -30,6 +29,7 @@ use std::{ pin::Pin, sync::Arc, }; +use tracing::trace; #[derive(Debug)] pub struct FileMeta { @@ -45,7 +45,7 @@ pub struct FileMeta { /// # Example usage /// /// ```rust -/// # use form_data::Value; +/// # use actix_form_data::Value; /// # use std::collections::HashMap; /// # let mut hm = HashMap::new(); /// # hm.insert("field-name".to_owned(), Value::Int(32)); @@ -206,17 +206,23 @@ impl Field { /// /// # Example /// ```rust - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// # use tokio::sync::mpsc::channel; + /// # use futures::stream::StreamExt; /// # /// let (tx, rx) = channel(1); - /// let form = Form::new().field("file-field", Field::file(|_, _, stream| async move { - /// while let Some(res) = stream.next().await { - /// if let Err(_) = tx.send(res).await { - /// break; + /// let form = Form::new().field("file-field", Field::file(move |_, _, mut stream| { + /// let mut tx = tx.clone(); + /// async move { + /// 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: F) -> Self @@ -239,7 +245,7 @@ impl Field { /// /// # Example /// ```rust - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// let form = Form::new().field("text-field", Field::bytes()); pub fn bytes() -> Self { Field::Bytes @@ -249,7 +255,7 @@ impl Field { /// /// # Example /// ```rust - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// let form = Form::new().field("text-field", Field::text()); pub fn text() -> Self { Field::Text @@ -259,7 +265,7 @@ impl Field { /// /// # Example /// ```rust - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// let form = Form::new().field("int-field", Field::int()); /// ``` pub fn int() -> Self { @@ -270,7 +276,7 @@ impl Field { /// /// # Example /// ```rust - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// let form = Form::new().field("float-field", Field::float()); /// ``` pub fn float() -> Self { @@ -281,8 +287,7 @@ impl Field { /// /// # Example /// ```rust - /// # extern crate form_data; - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// # fn main() { /// let form = Form::new() /// .field( @@ -299,8 +304,7 @@ impl Field { /// /// # Example /// ```rust - /// # extern crate form_data; - /// # use form_data::{Form, Field}; + /// # use actix_form_data::{Form, Field}; /// # fn main() { /// let form = Form::new() /// .field( @@ -402,7 +406,7 @@ impl Map { /// Add a `Field` to a map /// # Example /// ```rust - /// # use form_data::Field; + /// # use actix_form_data::Field; /// # /// Field::map() /// .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 /// ```rust - /// # use form_data::Field; + /// # use actix_form_data::Field; /// # /// Field::map() /// .field("sub-field", Field::text()) @@ -448,12 +452,14 @@ impl Map { /// /// # Example /// ```rust -/// # use form_data::{Form, Field}; +/// # use actix_form_data::{Form, Field}; /// let form = Form::new() /// .field("field-name", Field::text()) /// .field("second-field", Field::int()) /// .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( /// "map-field", /// Field::map()