hyper_multipart_rfc7578/
lib.rs

1// Copyright 2017 rust-multipart-rfc7578 Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8
9//! This crate contains an implementation of the multipart/form-data media
10//! type described in [RFC 7578](https://tools.ietf.org/html/rfc7578) for
11//! [hyper](https://hyper.rs/).
12//!
13//! ## Usage
14//!
15//! Declare the dependency:
16//!
17//! ```toml
18//! [dependencies]
19//! hyper-multipart-rfc7578 = "0.8"
20//! ```
21//!
22//! Import the crate:
23//!
24//! ```rust
25//! use hyper_multipart_rfc7578 as multipart;
26//! ```
27//!
28//! ## Example:
29//!
30//! With a custom client:
31//!
32//! ```rust
33//! use hyper_multipart_rfc7578 as hyper_multipart;
34//!
35//! use hyper::Request;
36//! use hyper_multipart::client::{self, multipart};
37//! use hyper_util::{
38//!     client::legacy::{connect::HttpConnector, Builder, Client},
39//!     rt::TokioExecutor,
40//! };
41//!
42//! #[tokio::main]
43//! async fn main() {
44//!     let client = Builder::new(TokioExecutor::new()).build_http();
45//!     let mut form = multipart::Form::default();
46//!
47//!     form.add_text("test", "Hello World");
48//!
49//!     let mut req_builder = Request::get("http://localhost/upload");
50//!     let req = form.set_body::<multipart::Body>(req_builder).unwrap();
51//!
52//!     if let Ok(_) = client.request(req).await {
53//!         println!("done...");
54//!     } else {
55//!         eprintln!("an error occurred");
56//!     }
57//! }
58//! ```
59//!
60//! With a default client:
61//!
62//! ```rust
63//! use hyper_multipart_rfc7578 as hyper_multipart;
64//!
65//! use hyper::Request;
66//! use hyper_util::{
67//!     client::legacy::{connect::HttpConnector, Builder, Client},
68//!     rt::TokioExecutor,
69//! };
70//!
71//! use hyper_multipart::client::{self, multipart};
72//!
73//! #[tokio::main]
74//! async fn main() {
75//!     let client = Builder::new(TokioExecutor::new()).build_http();
76//!     let mut form = multipart::Form::default();
77//!
78//!     form.add_text("test", "Hello World");
79//!
80//!     let mut req_builder = Request::get("http://localhost/upload");
81//!     let req = form.set_body::<multipart::Body>(req_builder).unwrap();
82//!
83//!     if let Ok(_) = client.request(req).await {
84//!         println!("done...");
85//!     } else {
86//!         eprintln!("an error occurred");
87//!     }
88//! }
89//! ```
90
91#![allow(clippy::needless_doctest_main)]
92
93use common_multipart_rfc7578 as common_multipart;
94
95mod body;
96
97pub mod client {
98    pub use crate::common_multipart::client::Error;
99
100    pub mod multipart {
101        pub use crate::body::Body;
102        pub use crate::common_multipart::client::multipart::{BoundaryGenerator, Form};
103    }
104}