alux_http/parts.rs
1//! States a body that arrives as parts, rather than one that arrives whole.
2
3use core::future::Future;
4
5/// States one part of a body that arrives as parts.
6///
7/// A part states what it was sent under, and it carries a body like any other. What it carries is
8/// produced over time, so reading it is [`ChunksAlg`](crate::ChunksAlg) again, one level down: a
9/// body of parts is a sequence, and so is each part's content.
10pub trait PartAlg {
11 /// What this part carries, read as the chunks it arrives in.
12 type Content;
13
14 /// Returns the name this part was sent under, where it states one.
15 fn part_name(&self) -> Option<&str>;
16
17 /// Returns the file name this part was sent under, where it states one.
18 fn part_file_name(&self) -> Option<&str>;
19
20 /// Returns the media type this part states, where it states one.
21 fn part_media_type(&self) -> Option<&str>;
22
23 /// Reads what this part carries.
24 fn part_content(self) -> Self::Content;
25}
26
27/// States how an argument is read from a body that arrives as parts.
28///
29/// This is the reading counterpart of a body answered over time. There, a domain states what it
30/// produces and an interpretation carries it; here, an interpretation produces the parts and a
31/// domain states what it makes of them. `Parts` is whichever reader the interpretation has, so a
32/// type stating this once is read the same way by every one of them.
33pub trait FromPartsAlg<Parts>: Sized {
34 /// What reading this argument states when the parts do not state it.
35 type Error;
36
37 /// Reads this argument from the parts a caller sent.
38 fn from_parts(parts: Parts) -> impl Future<Output = Result<Self, Self::Error>> + Send;
39}