Struct media_type::Value

source ·
pub struct Value<'a> { /* private fields */ }
Expand description

A parameter value section of a Mime.

Except for the charset parameter, parameters are compared case sensitive

Implementations

Returns the underlying representation.

The underlying representation differs from the content, as it can contain quotes surrounding the content and quoted-pairs, even if non of them are necessary to represent the content.

For example the representation r#""a\"\ b""# corresponds to the content r#""a" b"#. Another semantically equivalent (i.e. with the same content) representation is r#""a\" b""

Example
let mime = r#"text/plain; param="abc def""#.parse::<mime::Mime>().unwrap();
let param = mime.get_param("param").unwrap();
assert_eq!(param.as_str_repr(), r#""abc def""#);

Returns the content of this instance.

It differs to the representation in that it will remove the quotation marks from the quoted string and will “unquote” quoted pairs.

If the underlying representation is a quoted string containing quoted-pairs Cow::Owned is returned.

If the underlying representation is a quoted-string without quoted-pairs Cow::Borrowed is returned as normal str slicing can be used to strip the surrounding double quoted.

If the underlying representation is not a quoted-string Cow::Borrowed is returned, too.

Example
use std::borrow::Cow;

let raw_mime = r#"text/plain; p1="char is \""; p2="simple"; p3=simple2"#;
let mime = raw_mime.parse::<mime::Mime>().unwrap();

let param1 = mime.get_param("p1").unwrap();
let expected: Cow<'static, str> = Cow::Owned(r#"char is ""#.into());
assert_eq!(param1.to_content(), expected);

let param2 = mime.get_param("p2").unwrap();
assert_eq!(param2.to_content(), Cow::Borrowed("simple"));

let param3 = mime.get_param("p3").unwrap();
assert_eq!(param3.to_content(), Cow::Borrowed("simple2"));

Trait Implementations

compares this instance with other with a ascii case insensitive comparsion algorithm Read more
compares this instance with other with a ascii case insensitive comparsion algorithm Read more
compares this instance with other with a ascii case insensitive comparsion algorithm Read more
compares this instance with other with a ascii case insensitive comparsion algorithm Read more
compares this instance with other with a ascii case insensitive comparsion algorithm Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.