Update documentation.

This commit is contained in:
KAMADA Ken'ichi 2021-03-21 17:56:37 +09:00
parent 117e26a715
commit da36010bb9
6 changed files with 19 additions and 23 deletions

View File

@ -28,7 +28,7 @@ use std::error;
use std::fmt; use std::fmt;
use std::io; use std::io;
/// An error type returned when parsing Exif data. /// An error returned when parsing of Exif data fails.
#[derive(Debug)] #[derive(Debug)]
#[non_exhaustive] #[non_exhaustive]
pub enum Error { pub enum Error {

View File

@ -61,17 +61,14 @@
//! # let exif = Reader::new().read_from_container( //! # let exif = Reader::new().read_from_container(
//! # &mut std::io::BufReader::new(&file)).unwrap(); //! # &mut std::io::BufReader::new(&file)).unwrap();
//! # macro_rules! eprintln { ($($tt:tt)*) => (panic!($($tt)*)) } //! # macro_rules! eprintln { ($($tt:tt)*) => (panic!($($tt)*)) }
//! // Orientation is stored as a SHORT. //! // Orientation is stored as a SHORT. You could match `orientation.value`
//! // against `Value::Short`, but the standard recommends that readers
//! // should accept BYTE, SHORT, or LONG values for any unsigned integer
//! // field. `Value::get_uint` is provided for that purpose.
//! match exif.get_field(Tag::Orientation, In::PRIMARY) { //! match exif.get_field(Tag::Orientation, In::PRIMARY) {
//! Some(orientation) => //! Some(orientation) =>
//! // You could match `orientation.value` against `Value::Short`,
//! // but the standard recommends that BYTE, SHORT, or LONG should
//! // be accepted. `Value::get_uint` is provided for that purpose.
//! match orientation.value.get_uint(0) { //! match orientation.value.get_uint(0) {
//! Some(v @ 1..=8) => { //! Some(v @ 1..=8) => println!("Orientation {}", v),
//! println!("Orientation {}", v);
//! # assert_eq!(v, 1);
//! },
//! _ => eprintln!("Orientation value is broken"), //! _ => eprintln!("Orientation value is broken"),
//! }, //! },
//! None => eprintln!("Orientation tag is missing"), //! None => eprintln!("Orientation tag is missing"),
@ -80,11 +77,8 @@
//! match exif.get_field(Tag::XResolution, In::PRIMARY) { //! match exif.get_field(Tag::XResolution, In::PRIMARY) {
//! Some(xres) => //! Some(xres) =>
//! match xres.value { //! match xres.value {
//! Value::Rational(ref v) if !v.is_empty() => { //! Value::Rational(ref v) if !v.is_empty() =>
//! println!("XResolution {}", v[0]); //! println!("XResolution {}", v[0]),
//! # assert_eq!(v[0].num, 72);
//! # assert_eq!(v[0].denom, 1);
//! },
//! _ => eprintln!("XResolution value is broken"), //! _ => eprintln!("XResolution value is broken"),
//! }, //! },
//! None => eprintln!("XResolution tag is missing"), //! None => eprintln!("XResolution tag is missing"),

View File

@ -63,7 +63,7 @@ pub struct Reader {
} }
impl Reader { impl Reader {
/// Construct a new `Reader`. /// Constructs a new `Reader`.
pub fn new() -> Self { pub fn new() -> Self {
Self {} Self {}
} }

View File

@ -31,7 +31,7 @@ use crate::value;
use crate::value::Value; use crate::value::Value;
use crate::util::atou16; use crate::util::atou16;
/// A tag of a TIFF field. /// A tag of a TIFF/Exif field.
/// ///
/// Some well-known tags are provided as associated constants of /// Some well-known tags are provided as associated constants of
/// this type. The constant names follow the Exif specification /// this type. The constant names follow the Exif specification
@ -64,8 +64,8 @@ impl Tag {
/// # Examples /// # Examples
/// ``` /// ```
/// use exif::{Context, Tag}; /// use exif::{Context, Tag};
/// assert_eq!(Tag::DateTime.context(), Context::Tiff); /// assert_eq!(Tag::XResolution.context(), Context::Tiff);
/// assert_eq!(Tag::ExposureTime.context(), Context::Exif); /// assert_eq!(Tag::DateTimeOriginal.context(), Context::Exif);
/// ``` /// ```
#[inline] #[inline]
pub fn context(self) -> Context { pub fn context(self) -> Context {
@ -77,7 +77,8 @@ impl Tag {
/// # Examples /// # Examples
/// ``` /// ```
/// use exif::Tag; /// use exif::Tag;
/// assert_eq!(Tag::DateTime.number(), 0x132); /// assert_eq!(Tag::XResolution.number(), 0x11a);
/// assert_eq!(Tag::DateTimeOriginal.number(), 0x9003);
/// ``` /// ```
#[inline] #[inline]
pub fn number(self) -> u16 { pub fn number(self) -> u16 {
@ -91,7 +92,7 @@ impl Tag {
} }
/// Returns the default value of the tag. `None` is returned if /// Returns the default value of the tag. `None` is returned if
/// it is not defined in the standard or it depends on the context. /// it is not defined in the standard or it depends on another tag.
#[inline] #[inline]
pub fn default_value(&self) -> Option<Value> { pub fn default_value(&self) -> Option<Value> {
get_tag_info(*self).and_then(|ti| (&ti.default).into()) get_tag_info(*self).and_then(|ti| (&ti.default).into())
@ -781,6 +782,7 @@ fn d_planarcfg(w: &mut dyn fmt::Write, value: &Value) -> fmt::Result {
} }
// ResolutionUnit (TIFF 0x128) // ResolutionUnit (TIFF 0x128)
// FocalPlaneResolutionUnit (Exif 0xa210)
fn d_resunit(w: &mut dyn fmt::Write, value: &Value) -> fmt::Result { fn d_resunit(w: &mut dyn fmt::Write, value: &Value) -> fmt::Result {
let s = match value.get_uint(0) { let s = match value.get_uint(0) {
Some(1) => "no absolute unit", Some(1) => "no absolute unit",

View File

@ -98,7 +98,7 @@ impl IfdEntry {
} }
} }
/// A TIFF field. /// A TIFF/Exif field.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Field { pub struct Field {
/// The tag of this field. /// The tag of this field.
@ -109,7 +109,7 @@ pub struct Field {
pub value: Value, pub value: Value,
} }
/// The IFD number. /// An IFD number.
/// ///
/// The IFDs are indexed from 0. The 0th IFD is for the primary image /// The IFDs are indexed from 0. The 0th IFD is for the primary image
/// and the 1st one is for the thumbnail. Two associated constants, /// and the 1st one is for the thumbnail. Two associated constants,

View File

@ -29,7 +29,7 @@ use std::fmt::Write as _;
use crate::endian::Endian; use crate::endian::Endian;
/// Types and values of TIFF fields (for Exif attributes). /// A type and values of a TIFF/Exif field.
#[derive(Clone)] #[derive(Clone)]
pub enum Value { pub enum Value {
/// Vector of 8-bit unsigned integers. /// Vector of 8-bit unsigned integers.