Struct git_config_value::color::Attribute
source · pub struct Attribute { /* private fields */ }
Expand description
Discriminating enum for Color
attributes.
git-config
supports modifiers and their negators. The negating color
attributes are equivalent to having a no
or no-
prefix to the normal
variant.
Implementations§
source§impl Attribute
impl Attribute
pub const BOLD: Self = _
pub const DIM: Self = _
pub const ITALIC: Self = _
pub const UL: Self = _
pub const BLINK: Self = _
pub const REVERSE: Self = _
pub const STRIKE: Self = _
sourcepub const RESET: Self = _
pub const RESET: Self = _
Reset is special as we have to be able to parse it, without git actually doing anything with it
pub const NO_DIM: Self = _
pub const NO_BOLD: Self = _
pub const NO_ITALIC: Self = _
pub const NO_UL: Self = _
pub const NO_BLINK: Self = _
pub const NO_REVERSE: Self = _
pub const NO_STRIKE: Self = _
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Returns an empty set of flags.
Examples found in repository?
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
fn try_from(s: &BStr) -> Result<Self, Self::Error> {
let s = std::str::from_utf8(s).map_err(|err| color_err(s).with_err(err))?;
enum ColorItem {
Value(Name),
Attr(Attribute),
}
let items = s.split_whitespace().filter_map(|s| {
if s.is_empty() {
return None;
}
Some(
Name::from_str(s)
.map(ColorItem::Value)
.or_else(|_| Attribute::from_str(s).map(ColorItem::Attr)),
)
});
let mut foreground = None;
let mut background = None;
let mut attributes = Attribute::empty();
for item in items {
match item {
Ok(item) => match item {
ColorItem::Value(v) => {
if foreground.is_none() {
foreground = Some(v);
} else if background.is_none() {
background = Some(v);
} else {
return Err(color_err(s));
}
}
ColorItem::Attr(a) => attributes |= a,
},
Err(_) => return Err(color_err(s)),
}
}
Ok(Color {
foreground,
background,
attributes,
})
}
sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
Examples found in repository?
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut write_space = None;
for bit in 1..std::mem::size_of::<Attribute>() * 8 {
let attr = match Attribute::from_bits(1 << bit) {
Some(attr) => attr,
None => continue,
};
if self.contains(attr) {
if write_space.take().is_some() {
write!(f, " ")?
}
match attr {
Attribute::RESET => write!(f, "reset"),
Attribute::BOLD => write!(f, "bold"),
Attribute::NO_BOLD => write!(f, "nobold"),
Attribute::DIM => write!(f, "dim"),
Attribute::NO_DIM => write!(f, "nodim"),
Attribute::UL => write!(f, "ul"),
Attribute::NO_UL => write!(f, "noul"),
Attribute::BLINK => write!(f, "blink"),
Attribute::NO_BLINK => write!(f, "noblink"),
Attribute::REVERSE => write!(f, "reverse"),
Attribute::NO_REVERSE => write!(f, "noreverse"),
Attribute::ITALIC => write!(f, "italic"),
Attribute::NO_ITALIC => write!(f, "noitalic"),
Attribute::STRIKE => write!(f, "strike"),
Attribute::NO_STRIKE => write!(f, "nostrike"),
_ => unreachable!("BUG: add new attribute flag"),
}?;
write_space = Some(());
}
}
Ok(())
}
sourcepub const fn from_bits_truncate(bits: u32) -> Self
pub const fn from_bits_truncate(bits: u32) -> Self
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
sourcepub const unsafe fn from_bits_unchecked(bits: u32) -> Self
pub const unsafe fn from_bits_unchecked(bits: u32) -> Self
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
Safety
The caller of the bitflags!
macro can chose to allow or
disallow extra bits for their bitflags type.
The caller of from_bits_unchecked()
has to ensure that
all bits correspond to a defined flag or that extra bits
are valid for this bitflags type.
sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if no flags are currently stored.
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut write_space = None;
if let Some(fg) = self.foreground {
fg.fmt(f)?;
write_space = Some(());
}
if let Some(bg) = self.background {
if write_space.take().is_some() {
write!(f, " ")?;
}
bg.fmt(f)?;
write_space = Some(())
}
if !self.attributes.is_empty() {
if write_space.take().is_some() {
write!(f, " ")?;
}
self.attributes.fmt(f)?;
}
Ok(())
}
sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Returns true
if there are flags common to both self
and other
.
sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Returns true
if all of the flags in other
are contained within self
.
Examples found in repository?
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut write_space = None;
for bit in 1..std::mem::size_of::<Attribute>() * 8 {
let attr = match Attribute::from_bits(1 << bit) {
Some(attr) => attr,
None => continue,
};
if self.contains(attr) {
if write_space.take().is_some() {
write!(f, " ")?
}
match attr {
Attribute::RESET => write!(f, "reset"),
Attribute::BOLD => write!(f, "bold"),
Attribute::NO_BOLD => write!(f, "nobold"),
Attribute::DIM => write!(f, "dim"),
Attribute::NO_DIM => write!(f, "nodim"),
Attribute::UL => write!(f, "ul"),
Attribute::NO_UL => write!(f, "noul"),
Attribute::BLINK => write!(f, "blink"),
Attribute::NO_BLINK => write!(f, "noblink"),
Attribute::REVERSE => write!(f, "reverse"),
Attribute::NO_REVERSE => write!(f, "noreverse"),
Attribute::ITALIC => write!(f, "italic"),
Attribute::NO_ITALIC => write!(f, "noitalic"),
Attribute::STRIKE => write!(f, "strike"),
Attribute::NO_STRIKE => write!(f, "nostrike"),
_ => unreachable!("BUG: add new attribute flag"),
}?;
write_space = Some(());
}
}
Ok(())
}
sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Inserts or removes the specified flags depending on the passed value.
sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
Returns the intersection between the flags in self
and
other
.
Specifically, the returned set contains only the flags which are
present in both self
and other
.
This is equivalent to using the &
operator (e.g.
ops::BitAnd
), as in flags & other
.
sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
Returns the union of between the flags in self
and other
.
Specifically, the returned set contains all flags which are
present in either self
or other
, including any which are
present in both (see Self::symmetric_difference
if that
is undesirable).
This is equivalent to using the |
operator (e.g.
ops::BitOr
), as in flags | other
.
sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
Returns the difference between the flags in self
and other
.
Specifically, the returned set contains all flags present in
self
, except for the ones present in other
.
It is also conceptually equivalent to the “bit-clear” operation:
flags & !other
(and this syntax is also supported).
This is equivalent to using the -
operator (e.g.
ops::Sub
), as in flags - other
.
sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
Returns the symmetric difference between the flags
in self
and other
.
Specifically, the returned set contains the flags present which
are present in self
or other
, but that are not present in
both. Equivalently, it contains the flags present in exactly
one of the sets self
and other
.
This is equivalent to using the ^
operator (e.g.
ops::BitXor
), as in flags ^ other
.
sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
Returns the complement of this set of flags.
Specifically, the returned set contains all the flags which are
not set in self
, but which are allowed for this type.
Alternatively, it can be thought of as the set difference
between Self::all()
and self
(e.g. Self::all() - self
)
This is equivalent to using the !
operator (e.g.
ops::Not
), as in !flags
.
Trait Implementations§
source§impl BitAndAssign<Attribute> for Attribute
impl BitAndAssign<Attribute> for Attribute
source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
Disables all flags disabled in the set.
source§impl BitOrAssign<Attribute> for Attribute
impl BitOrAssign<Attribute> for Attribute
source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
Adds the set of flags.
source§impl BitXorAssign<Attribute> for Attribute
impl BitXorAssign<Attribute> for Attribute
source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
Toggles the set of flags.
source§impl Extend<Attribute> for Attribute
impl Extend<Attribute> for Attribute
source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl FromIterator<Attribute> for Attribute
impl FromIterator<Attribute> for Attribute
source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
source§impl Ord for Attribute
impl Ord for Attribute
source§impl PartialEq<Attribute> for Attribute
impl PartialEq<Attribute> for Attribute
source§impl PartialOrd<Attribute> for Attribute
impl PartialOrd<Attribute> for Attribute
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<Attribute> for Attribute
impl SubAssign<Attribute> for Attribute
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Disables all flags enabled in the set.