pub trait DecodePostField<Config>: Debug {
    // Required methods
    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;

    // Provided methods
    fn merge_multiple(self, _existing: Self) -> Result<Self, PostFieldError>
       where Self: Sized { ... }
    fn not_found(_: Config) -> Result<Self, PostFieldError>
       where Self: Sized { ... }
}
Expand description

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§

source

fn from_field(config: Config, content: &str) -> Result<Self, PostFieldError>where 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.

source

fn from_file<R>( 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§

source

fn merge_multiple(self, _existing: Self) -> Result<Self, PostFieldError>where 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.

source

fn not_found(_: Config) -> Result<Self, PostFieldError>where Self: Sized,

Called when no field is found in the POST input.

The default implementation returns MissingField.

Implementations on Foreign Types§

source§

impl DecodePostField<()> for i16

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for u16

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for f64

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for u32

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for String

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl<T, C> DecodePostField<C> for Option<T>where T: DecodePostField<C>,

source§

fn from_field(config: C, content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( config: C, file: R, filename: Option<&str>, mime: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

fn not_found(_: C) -> Result<Self, PostFieldError>

source§

impl DecodePostField<()> for bool

source§

fn from_field(_: (), _: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

fn merge_multiple(self, existing: bool) -> Result<bool, PostFieldError>

source§

fn not_found(_: ()) -> Result<Self, PostFieldError>

source§

impl DecodePostField<()> for f32

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for usize

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl<T, C> DecodePostField<C> for Vec<T>where T: DecodePostField<C>,

source§

fn from_field(config: C, content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( config: C, file: R, filename: Option<&str>, mime: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

fn merge_multiple(self, existing: Vec<T>) -> Result<Vec<T>, PostFieldError>

source§

fn not_found(_: C) -> Result<Self, PostFieldError>

source§

impl DecodePostField<()> for i32

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for i8

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for u8

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for i64

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for u64

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

source§

impl DecodePostField<()> for isize

source§

fn from_field(_: (), content: &str) -> Result<Self, PostFieldError>

source§

fn from_file<R>( _: (), _: R, _: Option<&str>, _: &str ) -> Result<Self, PostFieldError>where R: BufRead,

Implementors§