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

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.

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

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.

Called when no field is found in the POST input.

The default implementation returns MissingField.

Implementors