Trait rouille::input::post::DecodePostField
[−]
[src]
pub trait DecodePostField<Config>: Debug { fn from_field(config: Config, content: &str) -> Result<Self, PostFieldError>
where
Self: Sized; fn from_file<R>(
config: Config,
file: R,
filename: Option<&str>,
mime: &str
) -> Result<Self, PostFieldError>
where
Self: Sized,
R: BufRead; fn merge_multiple(self, _existing: Self) -> Result<Self, PostFieldError>
where
Self: Sized, { ... } fn not_found(_: Config) -> Result<Self, PostFieldError>
where
Self: Sized, { ... } }
Must be implemented on types used with the post_input!
macro.
The template parameter represents the type of a configuration object that can be passed by
the user when the macro is called. If the user doesn't pass any configuration, the expected
type is ()
.
Required Methods
fn from_field(config: Config, content: &str) -> Result<Self, PostFieldError> where
Self: Sized,
Self: Sized,
Called when a field with the given name is found in the POST input.
The value of content
is what the client sent. This function should attempt to parse it
into Self
or return an error if it couldn't. If Self
can't handle a field, then a
PostFieldError::WrongFieldType
error should be returned.
fn from_file<R>(
config: Config,
file: R,
filename: Option<&str>,
mime: &str
) -> Result<Self, PostFieldError> where
Self: Sized,
R: BufRead,
config: Config,
file: R,
filename: Option<&str>,
mime: &str
) -> Result<Self, PostFieldError> where
Self: Sized,
R: BufRead,
Called when a file with the given name is found in the POST input.
The file
is an object from which the body of the file can be read. The filename
and
mime
are also arbitrary values sent directly by the client, so you shouldn't trust them
blindly.
Note: The
file
object can typically read directly from the socket. But don't worry about doing something wrong, as there are protection mechanisms that will prevent you from reading too far.
This method should do something with the file (like storing it somewhere) and return a
Self
that will allow the user to manipulate the file that was uploaded.
If Self
can't handle a file, then a PostFieldError::WrongFieldType
error should
be returned.
Provided Methods
fn merge_multiple(self, _existing: Self) -> Result<Self, PostFieldError> where
Self: Sized,
Self: Sized,
When multiple fields with the same name are found in the client's input, rouille will build an object for each of them and then merge them with this method.
The default implementation returns UnexpectedMultipleValues
.
fn not_found(_: Config) -> Result<Self, PostFieldError> where
Self: Sized,
Self: Sized,
Called when no field is found in the POST input.
The default implementation returns MissingField
.
Implementors
impl DecodePostField<()> for u8
impl DecodePostField<()> for i8
impl DecodePostField<()> for u16
impl DecodePostField<()> for i16
impl DecodePostField<()> for u32
impl DecodePostField<()> for i32
impl DecodePostField<()> for u64
impl DecodePostField<()> for i64
impl DecodePostField<()> for usize
impl DecodePostField<()> for isize
impl DecodePostField<()> for f32
impl DecodePostField<()> for f64
impl DecodePostField<()> for String
impl<T, C> DecodePostField<C> for Option<T> where
T: DecodePostField<C>,impl DecodePostField<()> for bool
impl<T, C> DecodePostField<C> for Vec<T> where
T: DecodePostField<C>,impl DecodePostField<()> for BufferedFile