// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
$($t:tt)*
) => { // Declared in the scope of the `bitflags!` call // This type appears in the end-user's API
$crate::__declare_public_bitflags! {
$(#[$outer])*
$vis struct $BitFlags
}
// This is where new library trait implementations can be added
$crate::__impl_external_bitflags! {
InternalBitFlags: $T, $BitFlags {
$(
$(#[$inner $($args)*])* const $Flag;
)*
}
}
/// Implement functions on bitflags types. /// /// We need to be careful about adding new methods and trait implementations here because they /// could conflict with items added by the end-user. #[macro_export] #[doc(hidden)]
macro_rules! __impl_bitflags {
(
$(#[$outer:meta])*
$PublicBitFlags:ident: $T:ty { fn empty() $empty:block fn all() $all:block fn bits($bits0:ident) $bits:block fn from_bits($from_bits0:ident) $from_bits:block fn from_bits_truncate($from_bits_truncate0:ident) $from_bits_truncate:block fn from_bits_retain($from_bits_retain0:ident) $from_bits_retain:block fn from_name($from_name0:ident) $from_name:block fn is_empty($is_empty0:ident) $is_empty:block fn is_all($is_all0:ident) $is_all:block fn intersects($intersects0:ident, $intersects1:ident) $intersects:block fn contains($contains0:ident, $contains1:ident) $contains:block fn insert($insert0:ident, $insert1:ident) $insert:block fn remove($remove0:ident, $remove1:ident) $remove:block fn toggle($toggle0:ident, $toggle1:ident) $toggle:block fn set($set0:ident, $set1:ident, $set2:ident) $set:block fn intersection($intersection0:ident, $intersection1:ident) $intersection:block fn union($union0:ident, $union1:ident) $union:block fn difference($difference0:ident, $difference1:ident) $difference:block fn symmetric_difference($symmetric_difference0:ident, $symmetric_difference1:ident) $symmetric_difference:block fn complement($complement0:ident) $complement:block
}
) => { #[allow(dead_code, deprecated, unused_attributes)]
$(#[$outer])* impl $PublicBitFlags { /// Get a flags value with all bits unset. #[inline] pubconstfn empty() -> Self {
$empty
}
/// Get a flags value with all known bits set. #[inline] pubconstfn all() -> Self {
$all
}
/// Get the underlying bits value. /// /// The returned value is exactly the bits set in this flags value. #[inline] pubconstfn bits(&self) -> $T { let $bits0 = self;
$bits
}
/// Convert from a bits value. /// /// This method will return `None` if any unknown bits are set. #[inline] pubconstfn from_bits(bits: $T) -> $crate::__private::core::option::Option<Self> { let $from_bits0 = bits;
$from_bits
}
/// Convert from a bits value, unsetting any unknown bits. #[inline] pubconstfn from_bits_truncate(bits: $T) -> Self { let $from_bits_truncate0 = bits;
$from_bits_truncate
}
/// Convert from a bits value exactly. #[inline] pubconstfn from_bits_retain(bits: $T) -> Self { let $from_bits_retain0 = bits;
$from_bits_retain
}
/// Get a flags value with the bits of a flag with the given name set. /// /// This method will return `None` if `name` is empty or doesn't /// correspond to any named flag. #[inline] pubfn from_name(name: &str) -> $crate::__private::core::option::Option<Self> { let $from_name0 = name;
$from_name
}
/// Whether all bits in this flags value are unset. #[inline] pubconstfn is_empty(&self) -> bool { let $is_empty0 = self;
$is_empty
}
/// Whether all known bits in this flags value are set. #[inline] pubconstfn is_all(&self) -> bool { let $is_all0 = self;
$is_all
}
/// Whether any set bits in a source flags value are also set in a target flags value. #[inline] pubconstfn intersects(&self, other: Self) -> bool { let $intersects0 = self; let $intersects1 = other;
$intersects
}
/// Whether all set bits in a source flags value are also set in a target flags value. #[inline] pubconstfn contains(&self, other: Self) -> bool { let $contains0 = self; let $contains1 = other;
$contains
}
/// The bitwise or (`|`) of the bits in two flags values. #[inline] pubfn insert(&mutself, other: Self) { let $insert0 = self; let $insert1 = other;
$insert
}
/// The intersection of a source flags value with the complement of a target flags value (`&!`).> /// /// This method is not equivalent to `self & !other` when `other` has unknown bits set. /// `remove` won't truncate `other`, but the `!` operator will. #[inline] pubfn remove(&mutself, other: Self) { let $remove0 = self; let $remove1 = other;
$remove
}
/// The bitwise exclusive-or (`^`) of the bits in two flags values. #[inline] pubfn toggle(&mutself, other: Self) { let $toggle0 = self; let $toggle1 = other;
$toggle
}
/// Call `insert` when `value` is `true` or `remove` when `value` is `false`. #[inline] pubfn set(&mutself, other: Self, value: bool) { let $set0 = self; let $set1 = other; let $set2 = value;
$set
}
/// The bitwise and (`&`) of the bits in two flags values. #[inline] #[must_use] pubconstfn intersection(self, other: Self) -> Self { let $intersection0 = self; let $intersection1 = other;
$intersection
}
/// The bitwise or (`|`) of the bits in two flags values. #[inline] #[must_use] pubconstfn union(self, other: Self) -> Self { let $union0 = self; let $union1 = other;
$union
}
/// The intersection of a source flags value with the complement of a target flags value (`&!`).> /// /// This method is not equivalent to `self & !other` when `other` has unknown bits set. /// `difference` won't truncate `other`, but the `!` operator will. #[inline] #[must_use] pubconstfn difference(self, other: Self) -> Self { let $difference0 = self; let $difference1 = other;
$difference
}
/// The bitwise exclusive-or (`^`) of the bits in two flags values. #[inline] #[must_use] pubconstfn symmetric_difference(self, other: Self) -> Self { let $symmetric_difference0 = self; let $symmetric_difference1 = other;
$symmetric_difference
}
/// The bitwise negation (`!`) of the bits in a flags value, truncating the result. #[inline] #[must_use] pubconstfn complement(self) -> Self { let $complement0 = self;
$complement
}
}
};
}
/// A macro that processed the input to `bitflags!` and shuffles attributes around /// based on whether or not they're "expression-safe". /// /// This macro is a token-tree muncher that works on 2 levels: /// /// For each attribute, we explicitly match on its identifier, like `cfg` to determine /// whether or not it should be considered expression-safe. /// /// If you find yourself with an attribute that should be considered expression-safe /// and isn't, it can be added here. #[macro_export] #[doc(hidden)]
macro_rules! __bitflags_expr_safe_attrs { // Entrypoint: Move all flags and all attributes into `unprocessed` lists // where they'll be munched one-at-a-time
(
$(#[$inner:ident $($args:tt)*])*
{ $e:expr }
) => {
$crate::__bitflags_expr_safe_attrs! {
expr: { $e },
attrs: { // All attributes start here
unprocessed: [$(#[$inner $($args)*])*], // Attributes that are safe on expressions go here
processed: [],
},
}
}; // Process the next attribute on the current flag // `cfg`: The next flag should be propagated to expressions // NOTE: You can copy this rules block and replace `cfg` with // your attribute name that should be considered expression-safe
(
expr: { $e:expr },
attrs: {
unprocessed: [ // cfg matched here #[cfg $($args:tt)*]
$($attrs_rest:tt)*
],
processed: [$($expr:tt)*],
},
) => {
$crate::__bitflags_expr_safe_attrs! {
expr: { $e },
attrs: {
unprocessed: [
$($attrs_rest)*
],
processed: [
$($expr)* // cfg added here #[cfg $($args)*]
],
},
}
}; // Process the next attribute on the current flag // `$other`: The next flag should not be propagated to expressions
(
expr: { $e:expr },
attrs: {
unprocessed: [ // $other matched here #[$other:ident $($args:tt)*]
$($attrs_rest:tt)*
],
processed: [$($expr:tt)*],
},
) => {
$crate::__bitflags_expr_safe_attrs! {
expr: { $e },
attrs: {
unprocessed: [
$($attrs_rest)*
],
processed: [ // $other not added here
$($expr)*
],
},
}
}; // Once all attributes on all flags are processed, generate the actual code
(
expr: { $e:expr },
attrs: {
unprocessed: [],
processed: [$(#[$expr:ident $($exprargs:tt)*])*],
},
) => {
$(#[$expr $($exprargs)*])*
{ $e }
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.