Skip to content

Commit 36aedd4

Browse files
committed
Merge pull request #22 from thijsc/master
Implement Debug, Display and Error for ValueAccessError
2 parents 4184303 + 87dd4f8 commit 36aedd4

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/ordered.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,47 @@ use chrono::{DateTime, UTC};
22
use bson::{Array,Bson,Document};
33
use super::oid::ObjectId;
44
use std::collections::BTreeMap;
5-
use std::fmt::{Display, Error, Formatter};
5+
use std::error;
6+
use std::fmt;
7+
use std::fmt::{Debug, Display, Error, Formatter};
68
use std::iter::{FromIterator, Map};
79
use std::vec::IntoIter;
810
use std::slice;
911

1012
/// Error to indicate that either a value was empty or it contained an unexpected
1113
/// type, for use with the direct getters.
12-
#[derive(Debug,PartialEq)]
14+
#[derive(PartialEq)]
1315
pub enum ValueAccessError {
1416
NotPresent,
1517
UnexpectedType
1618
}
1719

1820
pub type ValueAccessResult<T> = Result<T, ValueAccessError>;
1921

22+
impl Debug for ValueAccessError {
23+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
24+
match *self {
25+
ValueAccessError::NotPresent => write!(f, "ValueAccessError: field is not present"),
26+
ValueAccessError::UnexpectedType => write!(f, "ValueAccessError: field does not have the expected type")
27+
}
28+
}
29+
}
30+
31+
impl Display for ValueAccessError {
32+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
33+
match *self {
34+
ValueAccessError::NotPresent => write!(f, "field is not present"),
35+
ValueAccessError::UnexpectedType => write!(f, "field does not have the expected type")
36+
}
37+
}
38+
}
39+
40+
impl error::Error for ValueAccessError {
41+
fn description(&self) -> &str {
42+
"Error to indicate that either a value was empty or it contained an unexpected type"
43+
}
44+
}
45+
2046
/// A BSON document represented as an associative BTree Map with insertion ordering.
2147
#[derive(Debug,Clone,PartialEq)]
2248
pub struct OrderedDocument {

0 commit comments

Comments
 (0)