From b6507cf1d34abf772f5fe9d6e0310a34a83eeda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sat, 14 Nov 2020 17:45:27 +0100 Subject: [PATCH] Add examples --- src/image.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/image.rs b/src/image.rs index 4c6a78cbae..74907edc9b 100644 --- a/src/image.rs +++ b/src/image.rs @@ -67,6 +67,15 @@ pub enum ImageFormat { impl ImageFormat { /// Return the image format specified by a path's file extension. + /// + /// # Example + /// + /// ``` + /// use image::ImageFormat; + /// + /// let format = ImageFormat::from_extension("jpg"); + /// assert_eq!(format, Some(ImageFormat::Jpeg)); + /// ``` #[inline] pub fn from_extension(ext: S) -> Option where S: AsRef { // thin wrapper function to strip generics @@ -94,6 +103,17 @@ impl ImageFormat { } /// Return the image format specified by the path's file extension. + /// + /// # Example + /// + /// ``` + /// use image::ImageFormat; + /// + /// let format = ImageFormat::from_path("images/ferris.png")?; + /// assert_eq!(format, ImageFormat::Png); + /// + /// # Ok::<(), image::error::ImageError>(()) + /// ``` #[inline] pub fn from_path

(path: P) -> ImageResult where P : AsRef { // thin wrapper function to strip generics