Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Nov 14, 2020
1 parent 3843286 commit b6507cf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(ext: S) -> Option<Self> where S: AsRef<OsStr> {
// thin wrapper function to strip generics
Expand Down Expand Up @@ -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<P>(path: P) -> ImageResult<Self> where P : AsRef<Path> {
// thin wrapper function to strip generics
Expand Down

0 comments on commit b6507cf

Please sign in to comment.