aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-11-16 10:28:21 -0800
committerZeyla Hellyer <[email protected]>2017-11-16 10:28:40 -0800
commit7a5aa3c57951ee5c7267fabf38f2729b06629b34 (patch)
treea6ee66602e4eee134b9c03ded02d96d433427d61
parentFix doc-tests (diff)
downloadserenity-7a5aa3c57951ee5c7267fabf38f2729b06629b34.tar.xz
serenity-7a5aa3c57951ee5c7267fabf38f2729b06629b34.zip
impl From<&Path> for http::AttachmentType
-rw-r--r--src/http/mod.rs6
-rw-r--r--tests/test_http.rs18
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,
+ });
+}