-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relationship between MediaType
and MediaTypeBuf
#13
Comments
Looking closer at the implementation, I see that So I guess that there's no way to get a |
OTOH, So using I guess the real tricky part is the inability to cast between the two. Are they mostly incompatible implementations? |
@WhyNotHugo |
I made the two separate types for different situations because it is impossible to accomplish both const-constructibility and owned-type in a single type. You can cast between let text_plain = MediaType::parse("text/plain; charset=UTF-8").unwrap();
let text_plain: MediaTypeBuf = text_plain.into();
let text_plain_ref: MediaType = text_plain.to_ref();
let text_plain_ref: MediaType = (&text_plain).into();
For the function parameter, I recommend to use |
I tried to think of
MediaType
andMediaTypeBuf
as analogous toPath
andPathBuf
or&str
andString
, but they don't seen to interact in the same way.Notably, I can write a function that takes either
&str
orString
:Or a function that takes
Path
andPathBuf
But I don't quite see the relationship between
MediaType
andMediaTypeBuf
. There don't seem tobe any methods to cast between one to the other.
MediaType
also doesn't have ato_str()
orsimilar function.
I'm trying to write a function where a mime type needs to be passed as parameter. Currently it
takes
mime_type: MimeType
, whereMimeType: AsRef<[u8]>
.Do you have any insight for me on this case? Do you think that
mediatype
is a good fit here, or am I trying to fix square peg into round hole?The text was updated successfully, but these errors were encountered: