nyquest_interface/
body.rs1use std::{borrow::Cow, fmt::Debug};
7
8#[cfg(feature = "multipart")]
9#[cfg_attr(docsrs, doc(cfg(feature = "multipart")))]
10mod multipart;
11#[cfg(feature = "multipart")]
12#[cfg_attr(docsrs, doc(cfg(feature = "multipart")))]
13pub use multipart::{Part, PartBody};
14
15#[doc(hidden)]
17pub struct StreamReader<S> {
18 pub stream: S,
20 pub content_length: Option<u64>,
22}
23
24pub enum Body<S> {
29 Bytes {
31 content: Cow<'static, [u8]>,
33 content_type: Cow<'static, str>,
35 },
36 Form {
38 fields: Vec<(Cow<'static, str>, Cow<'static, str>)>,
40 },
41 #[cfg(feature = "multipart")]
43 Multipart {
44 parts: Vec<Part<S>>,
46 },
47 #[doc(hidden)]
49 Stream(StreamReader<S>),
50}
51
52impl<S> Debug for StreamReader<S>
53where
54 S: Debug,
55{
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 f.debug_struct("StreamReader")
58 .field("stream", &self.stream)
59 .field("content_length", &self.content_length)
60 .finish()
61 }
62}
63
64impl<S> Debug for Body<S>
65where
66 S: Debug,
67{
68 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 match self {
70 Body::Bytes {
71 content,
72 content_type,
73 } => f
74 .debug_struct("Body::Bytes")
75 .field("content", content)
76 .field("content_type", content_type)
77 .finish(),
78 Body::Form { fields } => f
79 .debug_struct("Body::Form")
80 .field("fields", fields)
81 .finish(),
82 #[cfg(feature = "multipart")]
83 Body::Multipart { parts } => f
84 .debug_struct("Body::Multipart")
85 .field("parts", parts)
86 .finish(),
87 Body::Stream(stream) => f
88 .debug_struct("Body::Stream")
89 .field("stream", stream)
90 .finish(),
91 }
92 }
93}
94
95impl<S> Clone for Body<S>
96where
97 S: Clone,
98{
99 fn clone(&self) -> Self {
100 match self {
101 Body::Bytes {
102 content,
103 content_type,
104 } => Body::Bytes {
105 content: content.clone(),
106 content_type: content_type.clone(),
107 },
108 Body::Form { fields } => Body::Form {
109 fields: fields.clone(),
110 },
111 #[cfg(feature = "multipart")]
112 Body::Multipart { parts } => Body::Multipart {
113 parts: parts.clone(),
114 },
115 Body::Stream(stream) => Body::Stream(stream.clone()),
116 }
117 }
118}
119
120impl<S> Clone for StreamReader<S>
121where
122 S: Clone,
123{
124 fn clone(&self) -> Self {
125 Self {
126 stream: self.stream.clone(),
127 content_length: self.content_length,
128 }
129 }
130}