Adjusting the Display implementation.

Display will automatically implement the to_string functionality, so the
explicit implementation was removed.
This commit is contained in:
Myrddin Dundragon 2017-05-11 16:49:46 -04:00
parent 8efb6fedff
commit 8b5d5a9c57
2 changed files with 36 additions and 51 deletions

View File

@ -83,12 +83,6 @@ macro_rules! c_enum
$($name::$variant => {stringify!($variant)})*
}
}
/// Get a String representation of this variant.
pub fn to_string(&self) -> String
{
String::from(self.to_str())
}
}
impl ::std::fmt::Debug for $name

View File

@ -82,49 +82,6 @@ macro_rules! c_flags
self.bits
}
/// Turn the flag into a String representation of its self.
#[warn(unused_assignments)]
pub fn to_string(&self) -> String
{
let mut first: bool;
let mut string: String;
// Push the left bracket onto the string.
string = String::new();
string.push_str("{");
// Handle checking each flag to see if it
// is part of this flag.
first = true;
$(
if self.intersects($flag) == true
{
// If this is not the first flag,
// then add an OR symbol.
if first == false
{
string.push_str(" | ");
}
// Push the flags name onto the string.
string.push_str(stringify!($flag));
first = false;
}
)+
// No flags were set.
if first == true
{
// Put a space in the string.
string.push_str(" ");
}
// Push the right bracket onto the string
// and return it.
string.push_str("}");
string
}
/// Returns `true` if there are flags common to
/// both `self` and `other`; Otherwise, `false` is returned.
pub fn intersects(&self, other: $name) -> bool
@ -217,15 +174,49 @@ macro_rules! c_flags
{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
{
write!(f, "{}", self.to_string())
::std::fmt::Display::fmt(self, f)
}
}
impl ::std::fmt::Display for $name
{
#[warn(unused_assignments)]
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
{
write!(f, "{}", self.to_string())
let mut first: bool;
// Push the left bracket onto the string.
try!(write!(f, "{}", '{'));
// Handle checking each flag to see if it
// is part of this flag.
first = true;
$(
if self.intersects($flag) == true
{
// If this is not the first flag,
// then add an OR symbol.
if first == false
{
try!(write!(f, " | "));
}
// Push the flags name onto the string.
try!(write!(f, "{}", stringify!($flag)));
first = false;
}
)+
// No flags were set.
if first == true
{
// Put a space in the string.
try!(write!(f, " "));
}
// Push the right bracket onto the string
// and return it.
write!(f, "{}", '}')
}
}
}