Struct Part
pub struct Part { /* private fields */ }http and multipart only.Expand description
A single part of a multipart Form.
Built via text, bytes,
stream, or file. Customise with
with_file_name,
try_with_mime_str,
with_content_size, or
with_headers.
Implementations§
§impl Part
impl Part
pub fn stream<S, O, E>(stream: S) -> Part
pub fn stream<S, O, E>(stream: S) -> Part
Create a streaming part. The content size is unknown unless set
explicitly via with_content_size.
pub async fn file<P>(path: P) -> Result<Part, Error>
pub async fn file<P>(path: P) -> Result<Part, Error>
Create a part from a file. The filename is taken from the path’s last
component, the MIME type is inferred from the extension (falling back
to application/octet-stream), and the content size is read from
filesystem metadata.
Filenames are converted to UTF-8 using lossy replacement of any
non-UTF-8 bytes (relevant on Unix where filenames are arbitrary
byte sequences). If you need to preserve non-UTF-8 names verbatim,
build the Part yourself with Part::file and override the
name via Part::with_file_name from a known UTF-8 source.
The reported content_size is taken from filesystem metadata at
the moment of the call. Concurrent writers that change the file
size between this call and the body being sent can desynchronise
the advertised Content-Length from the actually-streamed bytes;
avoid passing a path to a file that may be modified mid-flight.
pub fn with_file_name(self, file_name: impl Into<Cow<'static, str>>) -> Part
pub fn with_file_name(self, file_name: impl Into<Cow<'static, str>>) -> Part
Filename used in the part’s Content-Disposition header.
Accepts anything that converts into Cow<'static, str> —
&'static str literals, owned String, or an explicit
Cow::Owned/Cow::Borrowed.
pub fn set_file_name(
&mut self,
file_name: impl Into<Cow<'static, str>>,
) -> &mut Part
pub fn set_file_name( &mut self, file_name: impl Into<Cow<'static, str>>, ) -> &mut Part
Filename used in the part’s Content-Disposition header.
Accepts anything that converts into Cow<'static, str> —
&'static str literals, owned String, or an explicit
Cow::Owned/Cow::Borrowed.
pub fn maybe_with_mime(self, mime: Option<Mime>) -> Part
pub fn maybe_with_mime(self, mime: Option<Mime>) -> Part
The part’s Content-Type, as a parsed Mime.
with_*/set_* set, without_*/unset_* clear any
previously-set value.
pub fn maybe_set_mime(&mut self, mime: Option<Mime>) -> &mut Part
pub fn maybe_set_mime(&mut self, mime: Option<Mime>) -> &mut Part
The part’s Content-Type, as a parsed Mime.
with_*/set_* set, without_*/unset_* clear any
previously-set value.
pub fn with_mime(self, mime: Mime) -> Part
pub fn with_mime(self, mime: Mime) -> Part
The part’s Content-Type, as a parsed Mime.
with_*/set_* set, without_*/unset_* clear any
previously-set value.
pub fn set_mime(&mut self, mime: Mime) -> &mut Part
pub fn set_mime(&mut self, mime: Mime) -> &mut Part
The part’s Content-Type, as a parsed Mime.
with_*/set_* set, without_*/unset_* clear any
previously-set value.
pub fn without_mime(self) -> Part
pub fn without_mime(self) -> Part
The part’s Content-Type, as a parsed Mime.
with_*/set_* set, without_*/unset_* clear any
previously-set value.
pub fn unset_mime(&mut self) -> &mut Part
pub fn unset_mime(&mut self) -> &mut Part
The part’s Content-Type, as a parsed Mime.
with_*/set_* set, without_*/unset_* clear any
previously-set value.
pub fn try_with_mime_str(self, mime_str: &str) -> Result<Part, FromStrError>
pub fn try_with_mime_str(self, mime_str: &str) -> Result<Part, FromStrError>
The part’s Content-Type parsed from a string such as
"image/png". Generates try_with_mime_str /
try_set_mime_str companions returning Result.
pub fn try_set_mime_str(
&mut self,
mime_str: &str,
) -> Result<&mut Part, FromStrError>
pub fn try_set_mime_str( &mut self, mime_str: &str, ) -> Result<&mut Part, FromStrError>
The part’s Content-Type parsed from a string such as
"image/png". Generates try_with_mime_str /
try_set_mime_str companions returning Result.
pub fn maybe_with_content_size(self, size: Option<u64>) -> Part
pub fn maybe_with_content_size(self, size: Option<u64>) -> Part
Known content size in bytes. For streaming parts this allows the
surrounding Form to advertise a Content-Length.
pub fn maybe_set_content_size(&mut self, size: Option<u64>) -> &mut Part
pub fn maybe_set_content_size(&mut self, size: Option<u64>) -> &mut Part
Known content size in bytes. For streaming parts this allows the
surrounding Form to advertise a Content-Length.
pub fn with_content_size(self, size: u64) -> Part
pub fn with_content_size(self, size: u64) -> Part
Known content size in bytes. For streaming parts this allows the
surrounding Form to advertise a Content-Length.
pub fn set_content_size(&mut self, size: u64) -> &mut Part
pub fn set_content_size(&mut self, size: u64) -> &mut Part
Known content size in bytes. For streaming parts this allows the
surrounding Form to advertise a Content-Length.
pub fn without_content_size(self) -> Part
pub fn without_content_size(self) -> Part
Known content size in bytes. For streaming parts this allows the
surrounding Form to advertise a Content-Length.
pub fn unset_content_size(&mut self) -> &mut Part
pub fn unset_content_size(&mut self) -> &mut Part
Known content size in bytes. For streaming parts this allows the
surrounding Form to advertise a Content-Length.
pub fn with_headers(self, headers: HeaderMap) -> Part
pub fn with_headers(self, headers: HeaderMap) -> Part
Replace the part’s headers (other than Content-Disposition and
Content-Type, which are derived from the part’s metadata).
RFC 7578 §4.8 states that headers other than Content-Disposition,
Content-Type, and (legacy) Content-Transfer-Encoding “MUST NOT be
included and MUST be ignored” by receivers. Custom headers are
allowed here for compatibility with non-standard receivers, but
strictly conforming peers will silently drop them.
pub fn set_headers(&mut self, headers: HeaderMap) -> &mut Part
pub fn set_headers(&mut self, headers: HeaderMap) -> &mut Part
Replace the part’s headers (other than Content-Disposition and
Content-Type, which are derived from the part’s metadata).
RFC 7578 §4.8 states that headers other than Content-Disposition,
Content-Type, and (legacy) Content-Transfer-Encoding “MUST NOT be
included and MUST be ignored” by receivers. Custom headers are
allowed here for compatibility with non-standard receivers, but
strictly conforming peers will silently drop them.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Part
impl !RefUnwindSafe for Part
impl Send for Part
impl !Sync for Part
impl Unpin for Part
impl UnsafeUnpin for Part
impl !UnwindSafe for Part
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer