fn parse_part_params(mut text: &str) -> PartWithParams {
    const TYPE_SEP: &str = ";type=";
    const FNAME_SEP: &str = ";filename=";

    let mut file_type = None;
    let mut file_name_header = None;

    // Look for parameters starting from the right.
    // Only look for a parameter as long as it hasn't been found yet.
    // (There may be a cleaner way, this is the best I could come up with.)
    let mut delims = vec![TYPE_SEP, FNAME_SEP];
    while let Some((pre, delim, post)) = rsplit_once_any(text, &delims) {
        match delim {
            TYPE_SEP => file_type = Some(post.to_owned()),
            FNAME_SEP => file_name_header = Some(post.to_owned()),
            _ => unreachable!(),
        }
        delims.retain(|&x| x != delim);
        text = pre;
    }

    PartWithParams {
        value: text.to_owned(),
        file_type,
        file_name_header,
    }
}
/// HTTPie's syntax for this is imitating curl's.
///
/// curl's syntax is pretty hairy. At the most basic level it's just key-value
/// pairs separated by semicolons, but:
/// - Values may be quoted. This stops spaces from being stripped and allows
///   you to put semicolons in values. (Between quotes, quotes and backslashes
///   have to be backslash-escaped.)
/// - If a key is not recognized then it's skipped with a warning.
///   - Unless it comes right after a mimetype, in which case it's seen as part
///     of the last value, because mimetypes can use the exact same syntax
///     (e.g. `text/html; charset=UTF-8`).
///     `;type=text/plain;filename=foobar` will send Content-Type `text/plain`
///     and filename `foobar`, but `;type=text/plain;foo=bar` will send
///     Content-Type `text/plain;foo=bar`.
///
/// We'll cut some corners and just split on ";type=" and ";filename=". That should
/// be good enough for most purposes. (HTTPie only splits on ";type=".)
HTTPie's syntax for this is imitating curl's.
curl's syntax is pretty hairy. At the most basic level it's just key-value
pairs separated by semicolons, but:
Values may be quoted. This stops spaces from being stripped and allows
you to put semicolons in values. (Between quotes, quotes and backslashes
have to be backslash-escaped.)
If a key is not recognized then it's skipped with a warning.

We'll cut some corners and just split on ";type=" and ";filename=". That should
be good enough for most purposes. (HTTPie only splits on ";type=".)
HTTPie ' s syntax for this is imitating curl ' s . curl ' s syntax is pretty hairy . At the most basic level it ' s just key - value pairs separated by semicolons but : Values may be quoted . This stops spaces from being stripped and allows you to put semicolons in values . ( Between quotes quotes and backslashes have to be backslash - escaped . ) If a key is not recognized then it ' s skipped with a warning . We ' ll cut some corners and just split on " ; type = " and " ; filename = " . That should be good enough for most purposes . ( HTTPie only splits on " ; type = " . )
fn parse_part_params(mut text: &str) -> PartWithParams {
    const TYPE_SEP: &str = ";type=";
    const FNAME_SEP: &str = ";filename=";
    let mut file_type = None;
    let mut file_name_header = None;
    // Look for parameters starting from the right.
    // Only look for a parameter as long as it hasn't been found yet.
    // (There may be a cleaner way, this is the best I could come up with.)
    let mut delims = vec![TYPE_SEP, FNAME_SEP];
    while let Some((pre, delim, post)) = rsplit_once_any(text, &delims) {
        match delim {
            TYPE_SEP => file_type = Some(post.to_owned()),
            FNAME_SEP => file_name_header = Some(post.to_owned()),
            _ => unreachable!(),
        }
        delims.retain(|&x| x != delim);
        text = pre;
    }
    PartWithParams {
        value: text.to_owned(),
        file_type,
        file_name_header,
    }
}
fn parse_part_params ( mut text : & str ) -> PartWithParams { const TYPE_SEP : & str = " " ; const FNAME_SEP : & str = " " ; let mut file_type = None ; let mut file_name_header = None ; // Look for parameters starting from the right. // Only look for a parameter as long as it hasn't been found yet. // (There may be a cleaner way, this is the best I could come up with.) let mut delims = vec ! [ TYPE_SEP FNAME_SEP ] ; while let Some ( ( pre , delim , post ) ) = rsplit_once_any ( text , & delims ) { match delim { TYPE_SEP => file_type = Some ( post . to_owned ( ) ) , FNAME_SEP => file_name_header = Some ( post . to_owned ( ) ) , _ => unreachable ! ( ) , } delims . retain ( | & x | x != delim ) ; text = pre ; } PartWithParams { value : text . to_owned ( ) , file_type , file_name_header , } }
HTTPie's syntax for this is imitating curl's.
HTTPie ' s syntax for this is imitating curl ' s .
text
&str
text
&str