1- use crate :: { bail , Body , Mime } ;
1+ use crate :: { Body , Mime } ;
22
33use std:: fmt:: { self , Debug } ;
4+ use std:: path:: Path ;
45
56/// A single multipart entry.
67///
@@ -12,33 +13,32 @@ pub struct Entry {
1213
1314impl Entry {
1415 /// Create a new `Entry`.
15- pub fn new ( name : impl AsRef < str > , body : impl Into < Body > ) -> Self {
16+ pub fn new < S , B > ( name : S , body : B ) -> Self
17+ where
18+ S : AsRef < str > ,
19+ B : Into < Body > ,
20+ {
1621 Self {
1722 name : name. as_ref ( ) . to_owned ( ) ,
1823 body : body. into ( ) ,
1924 }
2025 }
2126
2227 /// Create an empty `Entry`.
23- pub fn empty ( name : impl AsRef < str > ) -> Self {
24- Self {
25- name : name . as_ref ( ) . to_owned ( ) ,
26- body : Body :: empty ( ) ,
27- }
28+ pub fn empty < S > ( name : S ) -> Self
29+ where
30+ S : AsRef < str > ,
31+ {
32+ Self :: new ( name , Body :: empty ( ) )
2833 }
2934
3035 /// Create an `Entry` from a file.
31- ///
3236 #[ cfg( all( feature = "async_std" , not( target_os = "unknown" ) ) ) ]
33- pub async fn from_file < P > ( path : P ) -> crate :: Result < Self >
37+ pub async fn from_file < S , P > ( name : S , path : P ) -> crate :: Result < Self >
3438 where
35- P : AsRef < std:: path:: Path > ,
39+ S : AsRef < str > ,
40+ P : AsRef < Path > ,
3641 {
37- let path = path. as_ref ( ) ;
38- let name = match path. to_str ( ) {
39- Some ( p) => p. to_owned ( ) ,
40- None => bail ! ( "Could not convert file name to unicode" ) ,
41- } ;
4242 let body = Body :: from_file ( path) . await ?;
4343 Ok ( Self :: new ( name, body) )
4444 }
0 commit comments