tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lib.rs (1964B)


      1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
      2 // file at the top-level directory of this distribution and at
      3 // http://rust-lang.org/COPYRIGHT.
      4 //
      5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
      6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
      7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
      8 // option. This file may not be copied, modified, or distributed
      9 // except according to those terms.
     10 
     11 pub use bitflags::bitflags as bitflags2;
     12 pub use bitflags::parser;
     13 
     14 // Copy of the macro from bitflags 1.3.2, with the implicit derives
     15 // removed, because in 2.0, they're expected to be explicitly given
     16 // in the macro invocation. And because bitflags 1.3.2 itself always
     17 // adds an impl Debug, we need to remove #[derive(Debug)] from what
     18 // is passed in, which is what the __impl_bitflags_remove_derive_debug
     19 // macro does.
     20 #[macro_export(local_inner_macros)]
     21 macro_rules! bitflags {
     22    (
     23        $(#[$($outer:tt)+])*
     24        $vis:vis struct $BitFlags:ident: $T:ty {
     25            $(
     26                $(#[$inner:ident $($args:tt)*])*
     27                const $Flag:ident = $value:expr;
     28            )*
     29        }
     30 
     31        $($t:tt)*
     32    ) => {
     33        $(#[$($outer)+])*
     34        #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
     35        $vis struct $BitFlags($T);
     36 
     37        impl core::fmt::Debug for $BitFlags {
     38            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
     39                if self.is_empty() {
     40                    core::write!(f, "{:#x}", Self::empty().bits())
     41                } else {
     42                    $crate::parser::to_writer(self, f)
     43                }
     44            }
     45        }
     46 
     47        bitflags2! {
     48            impl $BitFlags: $T {
     49                $(
     50                    $(#[$inner $($args)*])*
     51                    const $Flag = $value;
     52                )*
     53            }
     54        }
     55 
     56        bitflags! {
     57            $($t)*
     58        }
     59    };
     60    () => {};
     61 }