Skip to content

Commit

Permalink
fix std::error::Error impl
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed Aug 29, 2019
1 parent 8861464 commit 8499f0c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions enumflags/src/fallible.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::convert::TryFrom;
use core::fmt;
use super::BitFlags;
use super::_internal::RawBitFlags;

Expand Down Expand Up @@ -47,9 +48,15 @@ impl<T: RawBitFlags> FromBitsError<T> {
}
}

impl<T: RawBitFlags + fmt::Debug> fmt::Display for FromBitsError<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "Invalid bits for {:?}: {:#b}", self.flags, self.invalid)
}
}

#[cfg(feature = "std")]
impl<T: RawBitFlags> std::error::Error for FromBitsError<T> {
impl<T: RawBitFlags + fmt::Debug> std::error::Error for FromBitsError<T> {
fn description(&self) -> &str {
"invalid bit representation"
"invalid bitflags representation"
}
}
2 changes: 1 addition & 1 deletion enumflags/src/formatting.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::fmt::{self, Debug, Binary};
use crate::{BitFlags, FromBitsError, _internal::RawBitFlags};
use crate::{BitFlags, _internal::RawBitFlags};

impl<T> fmt::Debug for BitFlags<T>
where
Expand Down
2 changes: 1 addition & 1 deletion enumflags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#![warn(missing_docs)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]

#[cfg(all(test, not(feature = "std")))]
#[cfg(any(test, feature = "std"))]
extern crate core;
use core::{cmp, ops};
use core::iter::FromIterator;
Expand Down

0 comments on commit 8499f0c

Please sign in to comment.