diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-04 13:51:53 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-04 14:38:24 -0700 |
| commit | d66adb4375a2280800fd3b6484fd00da5b552789 (patch) | |
| tree | 268926d39f4bcaf5fe3f1f44cc85b83781623adb /src/http | |
| parent | Remove a FQN usage in User::refresh (diff) | |
| download | serenity-d66adb4375a2280800fd3b6484fd00da5b552789.tar.xz serenity-d66adb4375a2280800fd3b6484fd00da5b552789.zip | |
Make http::AttachmentType only use borrowed values
With the way AttachmentType is meant to be used by `http::send_files`,
none of the values need to be moved, they only need to be borrowed.
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/mod.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 51bc153..a2575a0 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1428,8 +1428,8 @@ pub fn send_file<R: Read>(channel_id: u64, mut file: R, filename: &str, map: Jso /// if the file is too large to send. /// /// [`HttpError::InvalidRequest`]: enum.HttpError.html#variant.InvalidRequest -pub fn send_files<T: Into<AttachmentType>>(channel_id: u64, files: Vec<T>, map: JsonMap) - -> Result<Message> { +pub fn send_files<'a, T>(channel_id: u64, files: Vec<T>, map: JsonMap) + -> Result<Message> where T: Into<AttachmentType<'a>> { let uri = format!(api!("/channels/{}/messages"), channel_id); let url = match Url::parse(&uri) { Ok(url) => url, @@ -1605,29 +1605,31 @@ fn verify(expected_status_code: u16, mut response: HyperResponse) -> Result<()> Err(Error::Http(HttpError::InvalidRequest(response.status))) } +use std::path::Path; + /// Enum that allows a user to pass a `Path` or a `File` type to `send_files` -pub enum AttachmentType { +pub enum AttachmentType<'a> { /// Indicates that the `AttachmentType` is a `File` - File((File, String)), + File((&'a File, &'a str)), /// Indicates that the `AttachmentType` is a `Path` - Path(PathBuf), + Path(&'a Path), } -impl From<String> for AttachmentType { - fn from(s: String) -> AttachmentType { - AttachmentType::Path(PathBuf::from(&s)) +impl<'a> From<&'a str> for AttachmentType<'a> { + fn from(s: &'a str) -> AttachmentType { + AttachmentType::Path(Path::new(s)) } } -impl<'a> From<&'a str> for AttachmentType { - fn from(s: &'a str) -> AttachmentType { - AttachmentType::Path(PathBuf::from(s)) +impl<'a> From<&'a PathBuf> for AttachmentType<'a> { + fn from(pathbuf: &'a PathBuf) -> AttachmentType { + AttachmentType::Path(pathbuf.as_path()) } } -impl<'a> From<(File, &'a str)> for AttachmentType { - fn from(f: (File, &str)) -> AttachmentType { - AttachmentType::File((f.0, f.1.to_owned())) +impl<'a> From<(&'a File, &'a str)> for AttachmentType<'a> { + fn from(f: (&'a File, &'a str)) -> AttachmentType<'a> { + AttachmentType::File((f.0, f.1)) } } |