Hi Guys,
I implemented From<&'static str> for the enum Mime, but I get a error when call the .into() method:
#[derive(PartialEq, Debug)]
pub enum Mime{
Plain,
JSON,
HTML,
JavaScript,
PNG,
OctetStream,
Other(&'static str),
}
impl From<&'static str> for Mime {
fn from(s: &'static str) -> Mime {
match s {
"text/plain" => Mime::Plain,
"application/json" => Mime::JSON,
"text/html" => Mime::HTML,
"application/javascript" => Mime::JavaScript,
"image/png" => Mime::PNG,
"application/octet-stream" => Mime::OctetStream,
_ => Mime::Other(s),
}
}
}
#[cfg(test)]
mod tests{
use super::Mime;
#[test]
fn test_mime(){
let m = "text/plain";
assert_eq!(Mime::Plain, Mime::from(m));
let actual: &'static str = Mime::Plain.into();
assert_eq!(m, actual);
}
}
I got this error:
error[E0277]: the trait bound &str: std::convert::From<mime::Mime>
is not satisfied
--> src\mime.rs:33:48
|
33 | let actual: &'static str = Mime::Plain.into();
| ^^^^ the trait std::convert::From<mime::Mime>
is not implemented for &str
|
= note: std::convert::From<mime::Mime>
is implemented for &mut str
, but not for &str
= note: required because of the requirements on the impl of std::convert::Into<&str>
for mime::Mime
Thanks for help.