Skip to main content

Driver

Struct Driver 

Source
pub struct Driver<B: AsMut<[u8]> + AsRef<[u8]>, S: Sink> { /* private fields */ }
Available on crate feature alloc only.
Expand description

The one streaming implementation of the hook order: parser, inspector, sink, the text buffer, the sniff window, and the empty-file delay.

It takes its limits and policy from the parser. Because a PartHead cannot outlive the parse call that produced it, the driver copies each head once into an owned head and hands that copy to the delayed calls.

§Examples

use form_net::{Boundary, Driver, Limits, MemorySink, MultipartParser, NoInspector, Policy, Progress};

let parser = MultipartParser::new(Boundary::new(b"X")?, &Limits::DEFAULT, &Policy::DEFAULT)?;
let mut driver = Driver::new(parser, MemorySink::new());
let body = b"--X\r\nContent-Disposition: form-data; name=\"a\"\r\n\r\n1\r\n--X--";
let (consumed, progress) = driver.push(body, true, &mut NoInspector)?;
assert!(matches!(progress, Progress::Field { name: "a", value: b"1" }));
let (_, progress) = driver.push(&body[consumed..], true, &mut NoInspector)?;
assert!(matches!(progress, Progress::End));

Implementations§

Source§

impl<B: AsMut<[u8]> + AsRef<[u8]>, S: Sink> Driver<B, S>

Source

pub fn new(parser: MultipartParser<B>, sink: S) -> Self

A driver over parser writing files to sink.

Source

pub const fn parser(&self) -> &MultipartParser<B>

The parser.

Source

pub fn into_parts(self) -> (MultipartParser<B>, S)

The parser and the sink.

Source

pub fn push<'d, I: Inspector>( &'d mut self, input: &[u8], eof: bool, inspector: &mut I, ) -> Result<(usize, Progress<'d, S::Output>), FormError>

Feeds input and returns how much was consumed and what completed: a text field, a closed file (the sink’s output), a request for more input, or the end. eof = true says input ends the body.

§Errors

Every multipart error, Refused, and the sink’s errors. On error the sink has already been aborted and inspector.failed called; later calls return Poisoned.

Trait Implementations§

Source§

impl<B: AsMut<[u8]> + AsRef<[u8]>, S: Sink> Debug for Driver<B, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B, S> Freeze for Driver<B, S>
where MultipartParser<B>: Freeze, State<S>: Freeze,

§

impl<B, S> RefUnwindSafe for Driver<B, S>

§

impl<B, S> Send for Driver<B, S>
where MultipartParser<B>: Send, State<S>: Send,

§

impl<B, S> Sync for Driver<B, S>
where MultipartParser<B>: Sync, State<S>: Sync,

§

impl<B, S> Unpin for Driver<B, S>
where MultipartParser<B>: Unpin, State<S>: Unpin,

§

impl<B, S> UnsafeUnpin for Driver<B, S>

§

impl<B, S> UnwindSafe for Driver<B, S>
where MultipartParser<B>: UnwindSafe, State<S>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.