Skip to content

Commit 8499f0c

Browse files
committed
fix std::error::Error impl
1 parent 8861464 commit 8499f0c

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

enumflags/src/fallible.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::convert::TryFrom;
2+
use core::fmt;
23
use super::BitFlags;
34
use super::_internal::RawBitFlags;
45

@@ -47,9 +48,15 @@ impl<T: RawBitFlags> FromBitsError<T> {
4748
}
4849
}
4950

51+
impl<T: RawBitFlags + fmt::Debug> fmt::Display for FromBitsError<T> {
52+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
53+
write!(fmt, "Invalid bits for {:?}: {:#b}", self.flags, self.invalid)
54+
}
55+
}
56+
5057
#[cfg(feature = "std")]
51-
impl<T: RawBitFlags> std::error::Error for FromBitsError<T> {
58+
impl<T: RawBitFlags + fmt::Debug> std::error::Error for FromBitsError<T> {
5259
fn description(&self) -> &str {
53-
"invalid bit representation"
60+
"invalid bitflags representation"
5461
}
5562
}

enumflags/src/formatting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::fmt::{self, Debug, Binary};
2-
use crate::{BitFlags, FromBitsError, _internal::RawBitFlags};
2+
use crate::{BitFlags, _internal::RawBitFlags};
33

44
impl<T> fmt::Debug for BitFlags<T>
55
where

enumflags/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#![warn(missing_docs)]
4949
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
5050

51-
#[cfg(all(test, not(feature = "std")))]
51+
#[cfg(any(test, feature = "std"))]
5252
extern crate core;
5353
use core::{cmp, ops};
5454
use core::iter::FromIterator;

0 commit comments

Comments
 (0)