Skip to content

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-bhatt committed Nov 7, 2020
1 parent cbd9934 commit e652e12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
24 changes: 0 additions & 24 deletions src/event/displayerr.rs

This file was deleted.

34 changes: 29 additions & 5 deletions src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
mod attributes;
mod builder;
mod data;
mod displayerr;
mod event;
mod extensions;
#[macro_use]
mod format;
Expand All @@ -17,8 +15,6 @@ pub use attributes::{AttributeValue, AttributesReader, AttributesWriter};
pub use builder::Error as EventBuilderError;
pub use builder::EventBuilder;
pub use data::Data;
pub use displayerr::DisplayError;
pub use event::Event;
pub use extensions::ExtensionValue;
pub(crate) use message::EventBinarySerializer;
pub(crate) use message::EventStructuredSerializer;
Expand All @@ -45,9 +41,11 @@ pub(crate) use v10::EventFormatSerializer as EventFormatSerializerV10;
use chrono::{DateTime, Utc};
use delegate_attr::delegate;
use std::collections::HashMap;
use std::fmt;
//use std::fmt;
use std::prelude::v1::*;
use url::Url;

use core::fmt::{self,Debug, Display};
/// Data structure that represents a [CloudEvent](https://github.com/cloudevents/spec/blob/master/spec.md).
/// It provides methods to get the attributes through [`AttributesReader`]
/// and write them through [`AttributesWriter`].
Expand Down Expand Up @@ -239,6 +237,32 @@ impl Event {
}
}

// Facilitates compatibility with snafu::Error for external objects

#[derive(PartialEq, Eq, Clone)]
pub struct DisplayError<T>(pub T);

impl<T> Debug for DisplayError<T>
where
T: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T> Display for DisplayError<T>
where
T: Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T> snafu::Error for DisplayError<T> where T: Display + Debug {}


#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit e652e12

Please sign in to comment.