diff options
| -rw-r--r-- | src/http/mod.rs | 6 | ||||
| -rw-r--r-- | tests/test_http.rs | 18 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 9e8cba4..d79f7fd 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1893,6 +1893,12 @@ impl<'a> From<&'a str> for AttachmentType<'a> { fn from(s: &'a str) -> AttachmentType { AttachmentType::Path(Path::new(s)) } } +impl<'a> From<&'a Path> for AttachmentType<'a> { + fn from(path: &'a Path) -> AttachmentType { + AttachmentType::Path(path) + } +} + impl<'a> From<&'a PathBuf> for AttachmentType<'a> { fn from(pathbuf: &'a PathBuf) -> AttachmentType { AttachmentType::Path(pathbuf.as_path()) } } diff --git a/tests/test_http.rs b/tests/test_http.rs new file mode 100644 index 0000000..1389ef6 --- /dev/null +++ b/tests/test_http.rs @@ -0,0 +1,18 @@ +#![cfg(feature = "http")] + +extern crate serenity; + +use serenity::http::AttachmentType; +use std::path::Path; + +#[test] +fn test_attachment_type() { + assert!(match AttachmentType::from(Path::new("./dogs/corgis/kona.png")) { + AttachmentType::Path(_) => true, + _ => false, + }); + assert!(match AttachmentType::from("./cats/copycat.png") { + AttachmentType::Path(_) => true, + _ => false, + }); +} |