Backed out changeset c654a712755b (bug 1408461)

--HG--
extra : rebase_source : 623157bbabeec362882acc296b4d38e9ea20ddd7
This commit is contained in:
Sebastian Hengst 2017-10-18 18:28:01 +02:00
Родитель b470b5f4a4
Коммит 3bc133f2e6
25 изменённых файлов: 179 добавлений и 1700 удалений

Просмотреть файл

@ -1 +0,0 @@
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"e7a77c1800f9852e4c9a2acb9df041773ecd0bc005bd1b0657ae0512c67100ac","Cargo.toml":"f35826eec96c765ae8aee4f8a66c6b3cb0d918b49935baf05bae79b6df8e1077","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"602c63819e332e93c85dc8426db4855f18fe0fabbd642c5b2303ed83f1ba926f","src/example_generated.rs":"161b69d92cf6e5fa4b5dc30f06031f3a0fb590b44be2bcf0f31cb8be4fab36fa","src/lib.rs":"56e86a16356d9322fa6b4e9b910041e2e7558c08b52ffbdacc647eba36b37abc","tests/conflicting_trait_impls.rs":"79993ea67ef09a5f99fddd69d8b73b1c137e41d0e8f8535f03865d6766dcc498","tests/external.rs":"15f7901698e286197666ccd309ad1debd3c35eaff680ca090368494e8b06ccf2","tests/external_no_std.rs":"c3556fd19dd91d1b093eb6a65d09a9d0985544f0377ba3d30c0e265c956f7237","tests/i128_bitflags.rs":"c955ef2c9fd385848195bb416e660e946ccbe59acc87862ef2646eb082d82e3f"},"package":"4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"}

0
third_party/rust/bitflags-0.9.1/.cargo-ok поставляемый
Просмотреть файл

29
third_party/rust/bitflags-0.9.1/.travis.yml поставляемый
Просмотреть файл

@ -1,29 +0,0 @@
os:
- linux
- osx
language: rust
rust:
- stable
- beta
- nightly
sudo: false
before_script:
- pip install -v 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
- if [[ -e ~/Library/Python/2.7/bin ]]; then export PATH=~/Library/Python/2.7/bin:$PATH; fi
script:
- cargo build --verbose
- cargo test --verbose
- travis-cargo --only nightly test
- cargo doc --no-deps
after_success:
- travis-cargo --only nightly doc-upload
env:
global:
- TRAVIS_CARGO_NIGHTLY_FEATURE=unstable_testing
- secure: "DoZ8g8iPs+X3xEEucke0Ae02JbkQ1qd1SSv/L2aQqxULmREtRcbzRauhiT+ToQO5Ft1Lul8uck14nPfs4gMr/O3jFFBhEBVpSlbkJx7eNL3kwUdp95UNroA8I43xPN/nccJaHDN6TMTD3+uajTQTje2SyzOQP+1gvdKg17kguvE="
notifications:
email:
on_success: never

31
third_party/rust/bitflags-0.9.1/Cargo.toml поставляемый
Просмотреть файл

@ -1,31 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "bitflags"
version = "0.9.1"
authors = ["The Rust Project Developers"]
description = "A macro to generate structures which behave like bitflags.\n"
homepage = "https://github.com/rust-lang-nursery/bitflags"
documentation = "https://docs.rs/bitflags"
readme = "README.md"
keywords = ["bit", "bitmask", "bitflags"]
categories = ["no-std"]
license = "MIT/Apache-2.0"
repository = "https://github.com/rust-lang-nursery/bitflags"
[features]
example_generated = []
unstable_testing = []
default = ["example_generated"]
[badges.travis-ci]
repository = "rust-lang-nursery/bitflags"

201
third_party/rust/bitflags-0.9.1/LICENSE-APACHE поставляемый
Просмотреть файл

@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
third_party/rust/bitflags-0.9.1/LICENSE-MIT поставляемый
Просмотреть файл

@ -1,25 +0,0 @@
Copyright (c) 2014 The Rust Project Developers
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

24
third_party/rust/bitflags-0.9.1/README.md поставляемый
Просмотреть файл

@ -1,24 +0,0 @@
bitflags
========
A Rust macro to generate structures which behave like a set of bitflags
[![Build Status](https://travis-ci.org/rust-lang-nursery/bitflags.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/bitflags)
[Documentation](https://docs.rs/bitflags)
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
bitflags = "0.9"
```
and this to your crate root:
```rust
#[macro_use]
extern crate bitflags;
```

Просмотреть файл

@ -1,16 +0,0 @@
//! This module shows an example of code generated by the macro. **IT MUST NOT BE USED OUTSIDE THIS
//! CRATE**.
bitflags! {
/// This is the same `Flags` struct defined in the [crate level example](../index.html#example).
/// Note that this struct is just for documentation purposes only, it must not be used outside
/// this crate.
pub struct Flags: u32 {
const FLAG_A = 0b00000001;
const FLAG_B = 0b00000010;
const FLAG_C = 0b00000100;
const FLAG_ABC = FLAG_A.bits
| FLAG_B.bits
| FLAG_C.bits;
}
}

990
third_party/rust/bitflags-0.9.1/src/lib.rs поставляемый
Просмотреть файл

@ -1,990 +0,0 @@
// 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.
//! A typesafe bitmask flag generator useful for sets of C-style bitmask flags.
//! It can be used for creating typesafe wrappers around C APIs.
//!
//! The `bitflags!` macro generates a `struct` that manages a set of flags. The
//! flags should only be defined for integer types, otherwise unexpected type
//! errors may occur at compile time.
//!
//! # Example
//!
//! ```
//! #[macro_use]
//! extern crate bitflags;
//!
//! bitflags! {
//! struct Flags: u32 {
//! const FLAG_A = 0b00000001;
//! const FLAG_B = 0b00000010;
//! const FLAG_C = 0b00000100;
//! const FLAG_ABC = FLAG_A.bits
//! | FLAG_B.bits
//! | FLAG_C.bits;
//! }
//! }
//!
//! fn main() {
//! let e1 = FLAG_A | FLAG_C;
//! let e2 = FLAG_B | FLAG_C;
//! assert_eq!((e1 | e2), FLAG_ABC); // union
//! assert_eq!((e1 & e2), FLAG_C); // intersection
//! assert_eq!((e1 - e2), FLAG_A); // set difference
//! assert_eq!(!e2, FLAG_A); // set complement
//! }
//! ```
//!
//! See [`example_generated::Flags`](./example_generated/struct.Flags.html) for documentation of code
//! generated by the above `bitflags!` expansion.
//!
//! The generated `struct`s can also be extended with type and trait
//! implementations:
//!
//! ```
//! #[macro_use]
//! extern crate bitflags;
//!
//! use std::fmt;
//!
//! bitflags! {
//! struct Flags: u32 {
//! const FLAG_A = 0b00000001;
//! const FLAG_B = 0b00000010;
//! }
//! }
//!
//! impl Flags {
//! pub fn clear(&mut self) {
//! self.bits = 0; // The `bits` field can be accessed from within the
//! // same module where the `bitflags!` macro was invoked.
//! }
//! }
//!
//! impl fmt::Display for Flags {
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//! write!(f, "hi!")
//! }
//! }
//!
//! fn main() {
//! let mut flags = FLAG_A | FLAG_B;
//! flags.clear();
//! assert!(flags.is_empty());
//! assert_eq!(format!("{}", flags), "hi!");
//! assert_eq!(format!("{:?}", FLAG_A | FLAG_B), "FLAG_A | FLAG_B");
//! assert_eq!(format!("{:?}", FLAG_B), "FLAG_B");
//! }
//! ```
//!
//! # Visibility
//!
//! The generated struct and its associated flag constants are not exported
//! out of the current module by default. A definition can be exported out of
//! the current module by adding `pub` before `flags`:
//!
//! ```ignore
//! #[macro_use]
//! extern crate bitflags;
//!
//! mod example {
//! bitflags! {
//! pub struct Flags1: u32 {
//! const FLAG_A = 0b00000001;
//! }
//! }
//! bitflags! {
//! struct Flags2: u32 {
//! const FLAG_B = 0b00000010;
//! }
//! }
//! }
//!
//! fn main() {
//! let flag1 = example::FLAG_A;
//! let flag2 = example::FLAG_B; // error: const `FLAG_B` is private
//! }
//! ```
//!
//! # Attributes
//!
//! Attributes can be attached to the generated `struct` by placing them
//! before the `flags` keyword.
//!
//! # Trait implementations
//!
//! The `Copy`, `Clone`, `PartialEq`, `Eq`, `PartialOrd`, `Ord` and `Hash`
//! traits automatically derived for the `struct` using the `derive` attribute.
//! Additional traits can be derived by providing an explicit `derive`
//! attribute on `flags`.
//!
//! The `Extend` and `FromIterator` traits are implemented for the `struct`,
//! too: `Extend` adds the union of the instances of the `struct` iterated over,
//! while `FromIterator` calculates the union.
//!
//! The `Binary`, `Debug`, `LowerExp`, `Octal` and `UpperExp` trait is also
//! implemented by displaying the bits value of the internal struct.
//!
//! ## Operators
//!
//! The following operator traits are implemented for the generated `struct`:
//!
//! - `BitOr` and `BitOrAssign`: union
//! - `BitAnd` and `BitAndAssign`: intersection
//! - `BitXor` and `BitXorAssign`: toggle
//! - `Sub` and `SubAssign`: set difference
//! - `Not`: set complement
//!
//! # Methods
//!
//! The following methods are defined for the generated `struct`:
//!
//! - `empty`: an empty set of flags
//! - `all`: the set of all flags
//! - `bits`: the raw value of the flags currently stored
//! - `from_bits`: convert from underlying bit representation, unless that
//! representation contains bits that do not correspond to a flag
//! - `from_bits_truncate`: convert from underlying bit representation, dropping
//! any bits that do not correspond to flags
//! - `is_empty`: `true` if no flags are currently stored
//! - `is_all`: `true` if all flags are currently set
//! - `intersects`: `true` if there are flags common to both `self` and `other`
//! - `contains`: `true` all of the flags in `other` are contained within `self`
//! - `insert`: inserts the specified flags in-place
//! - `remove`: removes the specified flags in-place
//! - `toggle`: the specified flags will be inserted if not present, and removed
//! if they are.
//!
//! ## Default
//!
//! The `Default` trait is not automatically implemented for the generated struct.
//!
//! If your default value is equal to `0` (which is the same value as calling `empty()`
//! on the generated struct), you can simply derive `Default`:
//!
//! ```
//! #[macro_use]
//! extern crate bitflags;
//!
//! bitflags! {
//! // Results in default value with bits: 0
//! #[derive(Default)]
//! struct Flags: u32 {
//! const FLAG_A = 0b00000001;
//! const FLAG_B = 0b00000010;
//! const FLAG_C = 0b00000100;
//! }
//! }
//!
//! fn main() {
//! let derived_default: Flags = Default::default();
//! assert_eq!(derived_default.bits(), 0);
//! }
//! ```
//!
//! If your default value is not equal to `0` you need to implement `Default` yourself:
//!
//! ```
//! #[macro_use]
//! extern crate bitflags;
//!
//! bitflags! {
//! struct Flags: u32 {
//! const FLAG_A = 0b00000001;
//! const FLAG_B = 0b00000010;
//! const FLAG_C = 0b00000100;
//! }
//! }
//!
//! // explicit `Default` implementation
//! impl Default for Flags {
//! fn default() -> Flags {
//! FLAG_A | FLAG_C
//! }
//! }
//!
//! fn main() {
//! let implemented_default: Flags = Default::default();
//! assert_eq!(implemented_default, (FLAG_A | FLAG_C));
//! }
//! ```
#![no_std]
#![doc(html_root_url = "https://docs.rs/bitflags/0.9.1")]
// When compiled for the rustc compiler itself we want to make sure that this is
// an unstable crate.
#![cfg_attr(rustbuild, feature(staged_api))]
#![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]
#[cfg(test)]
#[macro_use]
extern crate std;
// Re-export libstd/libcore using an alias so that the macros can work in no_std
// crates while remaining compatible with normal crates.
#[doc(hidden)]
pub extern crate core as _core;
/// The macro used to generate the flag structure.
///
/// See the [crate level docs](../bitflags/index.html) for complete documentation.
///
/// # Example
///
/// ```
/// #[macro_use]
/// extern crate bitflags;
///
/// bitflags! {
/// struct Flags: u32 {
/// const FLAG_A = 0b00000001;
/// const FLAG_B = 0b00000010;
/// const FLAG_C = 0b00000100;
/// const FLAG_ABC = FLAG_A.bits
/// | FLAG_B.bits
/// | FLAG_C.bits;
/// }
/// }
///
/// fn main() {
/// let e1 = FLAG_A | FLAG_C;
/// let e2 = FLAG_B | FLAG_C;
/// assert_eq!((e1 | e2), FLAG_ABC); // union
/// assert_eq!((e1 & e2), FLAG_C); // intersection
/// assert_eq!((e1 - e2), FLAG_A); // set difference
/// assert_eq!(!e2, FLAG_A); // set complement
/// }
/// ```
///
/// The generated `struct`s can also be extended with type and trait
/// implementations:
///
/// ```
/// #[macro_use]
/// extern crate bitflags;
///
/// use std::fmt;
///
/// bitflags! {
/// struct Flags: u32 {
/// const FLAG_A = 0b00000001;
/// const FLAG_B = 0b00000010;
/// }
/// }
///
/// impl Flags {
/// pub fn clear(&mut self) {
/// self.bits = 0; // The `bits` field can be accessed from within the
/// // same module where the `bitflags!` macro was invoked.
/// }
/// }
///
/// impl fmt::Display for Flags {
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// write!(f, "hi!")
/// }
/// }
///
/// fn main() {
/// let mut flags = FLAG_A | FLAG_B;
/// flags.clear();
/// assert!(flags.is_empty());
/// assert_eq!(format!("{}", flags), "hi!");
/// assert_eq!(format!("{:?}", FLAG_A | FLAG_B), "FLAG_A | FLAG_B");
/// assert_eq!(format!("{:?}", FLAG_B), "FLAG_B");
/// }
/// ```
#[macro_export]
macro_rules! bitflags {
($(#[$attr:meta])* pub struct $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
}) => {
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
$(#[$attr])*
pub struct $BitFlags {
bits: $T,
}
$($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: $value };)+
__impl_bitflags! {
struct $BitFlags: $T {
$($(#[$Flag_attr])* const $Flag = $value;)+
}
}
};
($(#[$attr:meta])* struct $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
}) => {
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
$(#[$attr])*
struct $BitFlags {
bits: $T,
}
$($(#[$Flag_attr])* const $Flag: $BitFlags = $BitFlags { bits: $value };)+
__impl_bitflags! {
struct $BitFlags: $T {
$($(#[$Flag_attr])* const $Flag = $value;)+
}
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __impl_bitflags {
(struct $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
}) => {
impl $crate::_core::fmt::Debug for $BitFlags {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
// This convoluted approach is to handle #[cfg]-based flag
// omission correctly. For example it needs to support:
//
// #[cfg(unix)] const A: Flag = /* ... */;
// #[cfg(windows)] const B: Flag = /* ... */;
// Unconditionally define a check for every flag, even disabled
// ones.
#[allow(non_snake_case)]
trait __BitFlags {
$(
fn $Flag(&self) -> bool { false }
)+
}
// Conditionally override the check for just those flags that
// are not #[cfg]ed away.
impl __BitFlags for $BitFlags {
$(
$(#[$Flag_attr])*
fn $Flag(&self) -> bool {
self.bits & $Flag.bits == $Flag.bits
}
)+
}
let mut first = true;
$(
if <$BitFlags as __BitFlags>::$Flag(self) {
if !first {
try!(f.write_str(" | "));
}
first = false;
try!(f.write_str(stringify!($Flag)));
}
)+
if first {
try!(f.write_str("(empty)"));
}
Ok(())
}
}
impl $crate::_core::fmt::Binary for $BitFlags {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
$crate::_core::fmt::Binary::fmt(&self.bits, f)
}
}
impl $crate::_core::fmt::Octal for $BitFlags {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
$crate::_core::fmt::Octal::fmt(&self.bits, f)
}
}
impl $crate::_core::fmt::LowerHex for $BitFlags {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
$crate::_core::fmt::LowerHex::fmt(&self.bits, f)
}
}
impl $crate::_core::fmt::UpperHex for $BitFlags {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
$crate::_core::fmt::UpperHex::fmt(&self.bits, f)
}
}
#[allow(dead_code)]
impl $BitFlags {
/// Returns an empty set of flags.
#[inline]
pub fn empty() -> $BitFlags {
$BitFlags { bits: 0 }
}
/// Returns the set containing all flags.
#[inline]
pub fn all() -> $BitFlags {
// See `Debug::fmt` for why this approach is taken.
#[allow(non_snake_case)]
trait __BitFlags {
$(
fn $Flag() -> $T { 0 }
)+
}
impl __BitFlags for $BitFlags {
$(
$(#[$Flag_attr])*
fn $Flag() -> $T { $Flag.bits }
)+
}
$BitFlags { bits: $(<$BitFlags as __BitFlags>::$Flag())|+ }
}
/// Returns the raw value of the flags currently stored.
#[inline]
pub fn bits(&self) -> $T {
self.bits
}
/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
#[inline]
pub fn from_bits(bits: $T) -> $crate::_core::option::Option<$BitFlags> {
if (bits & !$BitFlags::all().bits()) == 0 {
$crate::_core::option::Option::Some($BitFlags { bits: bits })
} else {
$crate::_core::option::Option::None
}
}
/// Convert from underlying bit representation, dropping any bits
/// that do not correspond to flags.
#[inline]
pub fn from_bits_truncate(bits: $T) -> $BitFlags {
$BitFlags { bits: bits } & $BitFlags::all()
}
/// Returns `true` if no flags are currently stored.
#[inline]
pub fn is_empty(&self) -> bool {
*self == $BitFlags::empty()
}
/// Returns `true` if all flags are currently set.
#[inline]
pub fn is_all(&self) -> bool {
*self == $BitFlags::all()
}
/// Returns `true` if there are flags common to both `self` and `other`.
#[inline]
pub fn intersects(&self, other: $BitFlags) -> bool {
!(*self & other).is_empty()
}
/// Returns `true` all of the flags in `other` are contained within `self`.
#[inline]
pub fn contains(&self, other: $BitFlags) -> bool {
(*self & other) == other
}
/// Inserts the specified flags in-place.
#[inline]
pub fn insert(&mut self, other: $BitFlags) {
self.bits |= other.bits;
}
/// Removes the specified flags in-place.
#[inline]
pub fn remove(&mut self, other: $BitFlags) {
self.bits &= !other.bits;
}
/// Toggles the specified flags in-place.
#[inline]
pub fn toggle(&mut self, other: $BitFlags) {
self.bits ^= other.bits;
}
/// Inserts or removes the specified flags depending on the passed value.
#[inline]
pub fn set(&mut self, other: $BitFlags, value: bool) {
if value {
self.insert(other);
} else {
self.remove(other);
}
}
}
impl $crate::_core::ops::BitOr for $BitFlags {
type Output = $BitFlags;
/// Returns the union of the two sets of flags.
#[inline]
fn bitor(self, other: $BitFlags) -> $BitFlags {
$BitFlags { bits: self.bits | other.bits }
}
}
impl $crate::_core::ops::BitOrAssign for $BitFlags {
/// Adds the set of flags.
#[inline]
fn bitor_assign(&mut self, other: $BitFlags) {
self.bits |= other.bits;
}
}
impl $crate::_core::ops::BitXor for $BitFlags {
type Output = $BitFlags;
/// Returns the left flags, but with all the right flags toggled.
#[inline]
fn bitxor(self, other: $BitFlags) -> $BitFlags {
$BitFlags { bits: self.bits ^ other.bits }
}
}
impl $crate::_core::ops::BitXorAssign for $BitFlags {
/// Toggles the set of flags.
#[inline]
fn bitxor_assign(&mut self, other: $BitFlags) {
self.bits ^= other.bits;
}
}
impl $crate::_core::ops::BitAnd for $BitFlags {
type Output = $BitFlags;
/// Returns the intersection between the two sets of flags.
#[inline]
fn bitand(self, other: $BitFlags) -> $BitFlags {
$BitFlags { bits: self.bits & other.bits }
}
}
impl $crate::_core::ops::BitAndAssign for $BitFlags {
/// Disables all flags disabled in the set.
#[inline]
fn bitand_assign(&mut self, other: $BitFlags) {
self.bits &= other.bits;
}
}
impl $crate::_core::ops::Sub for $BitFlags {
type Output = $BitFlags;
/// Returns the set difference of the two sets of flags.
#[inline]
fn sub(self, other: $BitFlags) -> $BitFlags {
$BitFlags { bits: self.bits & !other.bits }
}
}
impl $crate::_core::ops::SubAssign for $BitFlags {
/// Disables all flags enabled in the set.
#[inline]
fn sub_assign(&mut self, other: $BitFlags) {
self.bits &= !other.bits;
}
}
impl $crate::_core::ops::Not for $BitFlags {
type Output = $BitFlags;
/// Returns the complement of this set of flags.
#[inline]
fn not(self) -> $BitFlags {
$BitFlags { bits: !self.bits } & $BitFlags::all()
}
}
impl $crate::_core::iter::Extend<$BitFlags> for $BitFlags {
fn extend<T: $crate::_core::iter::IntoIterator<Item=$BitFlags>>(&mut self, iterator: T) {
for item in iterator {
self.insert(item)
}
}
}
impl $crate::_core::iter::FromIterator<$BitFlags> for $BitFlags {
fn from_iter<T: $crate::_core::iter::IntoIterator<Item=$BitFlags>>(iterator: T) -> $BitFlags {
let mut result = Self::empty();
result.extend(iterator);
result
}
}
};
}
#[cfg(feature = "example_generated")]
pub mod example_generated;
#[cfg(test)]
#[allow(non_upper_case_globals, dead_code)]
mod tests {
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
bitflags! {
#[doc = "> The first principle is that you must not fool yourself — and"]
#[doc = "> you are the easiest person to fool."]
#[doc = "> "]
#[doc = "> - Richard Feynman"]
struct Flags: u32 {
const FlagA = 0b00000001;
#[doc = "<pcwalton> macros are way better at generating code than trans is"]
const FlagB = 0b00000010;
const FlagC = 0b00000100;
#[doc = "* cmr bed"]
#[doc = "* strcat table"]
#[doc = "<strcat> wait what?"]
const FlagABC = FlagA.bits
| FlagB.bits
| FlagC.bits;
}
}
bitflags! {
struct _CfgFlags: u32 {
#[cfg(windows)]
const _CfgA = 0b01;
#[cfg(unix)]
const _CfgB = 0b01;
#[cfg(windows)]
const _CfgC = _CfgA.bits | 0b10;
}
}
bitflags! {
struct AnotherSetOfFlags: i8 {
const AnotherFlag = -1_i8;
}
}
bitflags! {
struct LongFlags: u32 {
const LongFlagA = 0b1111111111111111;
}
}
#[test]
fn test_bits(){
assert_eq!(Flags::empty().bits(), 0b00000000);
assert_eq!(FlagA.bits(), 0b00000001);
assert_eq!(FlagABC.bits(), 0b00000111);
assert_eq!(AnotherSetOfFlags::empty().bits(), 0b00);
assert_eq!(AnotherFlag.bits(), !0_i8);
}
#[test]
fn test_from_bits() {
assert_eq!(Flags::from_bits(0), Some(Flags::empty()));
assert_eq!(Flags::from_bits(0b1), Some(FlagA));
assert_eq!(Flags::from_bits(0b10), Some(FlagB));
assert_eq!(Flags::from_bits(0b11), Some(FlagA | FlagB));
assert_eq!(Flags::from_bits(0b1000), None);
assert_eq!(AnotherSetOfFlags::from_bits(!0_i8), Some(AnotherFlag));
}
#[test]
fn test_from_bits_truncate() {
assert_eq!(Flags::from_bits_truncate(0), Flags::empty());
assert_eq!(Flags::from_bits_truncate(0b1), FlagA);
assert_eq!(Flags::from_bits_truncate(0b10), FlagB);
assert_eq!(Flags::from_bits_truncate(0b11), (FlagA | FlagB));
assert_eq!(Flags::from_bits_truncate(0b1000), Flags::empty());
assert_eq!(Flags::from_bits_truncate(0b1001), FlagA);
assert_eq!(AnotherSetOfFlags::from_bits_truncate(0_i8), AnotherSetOfFlags::empty());
}
#[test]
fn test_is_empty(){
assert!(Flags::empty().is_empty());
assert!(!FlagA.is_empty());
assert!(!FlagABC.is_empty());
assert!(!AnotherFlag.is_empty());
}
#[test]
fn test_is_all() {
assert!(Flags::all().is_all());
assert!(!FlagA.is_all());
assert!(FlagABC.is_all());
assert!(AnotherFlag.is_all());
}
#[test]
fn test_two_empties_do_not_intersect() {
let e1 = Flags::empty();
let e2 = Flags::empty();
assert!(!e1.intersects(e2));
assert!(AnotherFlag.intersects(AnotherFlag));
}
#[test]
fn test_empty_does_not_intersect_with_full() {
let e1 = Flags::empty();
let e2 = FlagABC;
assert!(!e1.intersects(e2));
}
#[test]
fn test_disjoint_intersects() {
let e1 = FlagA;
let e2 = FlagB;
assert!(!e1.intersects(e2));
}
#[test]
fn test_overlapping_intersects() {
let e1 = FlagA;
let e2 = FlagA | FlagB;
assert!(e1.intersects(e2));
}
#[test]
fn test_contains() {
let e1 = FlagA;
let e2 = FlagA | FlagB;
assert!(!e1.contains(e2));
assert!(e2.contains(e1));
assert!(FlagABC.contains(e2));
assert!(AnotherFlag.contains(AnotherFlag));
}
#[test]
fn test_insert(){
let mut e1 = FlagA;
let e2 = FlagA | FlagB;
e1.insert(e2);
assert_eq!(e1, e2);
let mut e3 = AnotherSetOfFlags::empty();
e3.insert(AnotherFlag);
assert_eq!(e3, AnotherFlag);
}
#[test]
fn test_remove(){
let mut e1 = FlagA | FlagB;
let e2 = FlagA | FlagC;
e1.remove(e2);
assert_eq!(e1, FlagB);
let mut e3 = AnotherFlag;
e3.remove(AnotherFlag);
assert_eq!(e3, AnotherSetOfFlags::empty());
}
#[test]
fn test_operators() {
let e1 = FlagA | FlagC;
let e2 = FlagB | FlagC;
assert_eq!((e1 | e2), FlagABC); // union
assert_eq!((e1 & e2), FlagC); // intersection
assert_eq!((e1 - e2), FlagA); // set difference
assert_eq!(!e2, FlagA); // set complement
assert_eq!(e1 ^ e2, FlagA | FlagB); // toggle
let mut e3 = e1;
e3.toggle(e2);
assert_eq!(e3, FlagA | FlagB);
let mut m4 = AnotherSetOfFlags::empty();
m4.toggle(AnotherSetOfFlags::empty());
assert_eq!(m4, AnotherSetOfFlags::empty());
}
#[test]
fn test_set() {
let mut e1 = FlagA | FlagC;
e1.set(FlagB, true);
e1.set(FlagC, false);
assert_eq!(e1, FlagA | FlagB);
}
#[test]
fn test_assignment_operators() {
let mut m1 = Flags::empty();
let e1 = FlagA | FlagC;
// union
m1 |= FlagA;
assert_eq!(m1, FlagA);
// intersection
m1 &= e1;
assert_eq!(m1, FlagA);
// set difference
m1 -= m1;
assert_eq!(m1, Flags::empty());
// toggle
m1 ^= e1;
assert_eq!(m1, e1);
}
#[test]
fn test_extend() {
let mut flags;
flags = Flags::empty();
flags.extend([].iter().cloned());
assert_eq!(flags, Flags::empty());
flags = Flags::empty();
flags.extend([FlagA, FlagB].iter().cloned());
assert_eq!(flags, FlagA | FlagB);
flags = FlagA;
flags.extend([FlagA, FlagB].iter().cloned());
assert_eq!(flags, FlagA | FlagB);
flags = FlagB;
flags.extend([FlagA, FlagABC].iter().cloned());
assert_eq!(flags, FlagABC);
}
#[test]
fn test_from_iterator() {
assert_eq!([].iter().cloned().collect::<Flags>(), Flags::empty());
assert_eq!([FlagA, FlagB].iter().cloned().collect::<Flags>(), FlagA | FlagB);
assert_eq!([FlagA, FlagABC].iter().cloned().collect::<Flags>(), FlagABC);
}
#[test]
fn test_lt() {
let mut a = Flags::empty();
let mut b = Flags::empty();
assert!(!(a < b) && !(b < a));
b = FlagB;
assert!(a < b);
a = FlagC;
assert!(!(a < b) && b < a);
b = FlagC | FlagB;
assert!(a < b);
}
#[test]
fn test_ord() {
let mut a = Flags::empty();
let mut b = Flags::empty();
assert!(a <= b && a >= b);
a = FlagA;
assert!(a > b && a >= b);
assert!(b < a && b <= a);
b = FlagB;
assert!(b > a && b >= a);
assert!(a < b && a <= b);
}
fn hash<T: Hash>(t: &T) -> u64 {
let mut s = DefaultHasher::new();
t.hash(&mut s);
s.finish()
}
#[test]
fn test_hash() {
let mut x = Flags::empty();
let mut y = Flags::empty();
assert_eq!(hash(&x), hash(&y));
x = Flags::all();
y = FlagABC;
assert_eq!(hash(&x), hash(&y));
}
#[test]
fn test_debug() {
assert_eq!(format!("{:?}", FlagA | FlagB), "FlagA | FlagB");
assert_eq!(format!("{:?}", Flags::empty()), "(empty)");
assert_eq!(format!("{:?}", FlagABC), "FlagA | FlagB | FlagC | FlagABC");
}
#[test]
fn test_binary() {
assert_eq!(format!("{:b}", FlagABC), "111");
assert_eq!(format!("{:#b}", FlagABC), "0b111");
}
#[test]
fn test_octal() {
assert_eq!(format!("{:o}", LongFlagA), "177777");
assert_eq!(format!("{:#o}", LongFlagA), "0o177777");
}
#[test]
fn test_lowerhex() {
assert_eq!(format!("{:x}", LongFlagA), "ffff");
assert_eq!(format!("{:#x}", LongFlagA), "0xffff");
}
#[test]
fn test_upperhex() {
assert_eq!(format!("{:X}", LongFlagA), "FFFF");
assert_eq!(format!("{:#X}", LongFlagA), "0xFFFF");
}
mod submodule {
bitflags! {
pub struct PublicFlags: i8 {
const FlagX = 0;
}
}
bitflags! {
struct PrivateFlags: i8 {
const FlagY = 0;
}
}
#[test]
fn test_private() {
let _ = FlagY;
}
}
#[test]
fn test_public() {
let _ = submodule::FlagX;
}
mod t1 {
mod foo {
pub type Bar = i32;
}
bitflags! {
/// baz
struct Flags: foo::Bar {
const A = 0b00000001;
#[cfg(foo)]
const B = 0b00000010;
#[cfg(foo)]
const C = 0b00000010;
}
}
}
#[test]
fn test_in_function() {
bitflags! {
struct Flags: u8 {
const A = 1;
#[cfg(any())] // false
const B = 2;
}
}
assert_eq!(Flags::all(), A);
assert_eq!(format!("{:?}", A), "A");
}
}

Просмотреть файл

@ -1,20 +0,0 @@
#![allow(dead_code)]
#![no_std]
#[macro_use]
extern crate bitflags;
#[allow(unused_imports)]
use core::fmt::Display;
bitflags! {
/// baz
struct Flags: u32 {
const A = 0b00000001;
}
}
#[test]
fn main() {
}

Просмотреть файл

@ -1,21 +0,0 @@
#![allow(dead_code)]
#[macro_use]
extern crate bitflags;
bitflags! {
/// baz
struct Flags: u32 {
const A = 0b00000001;
#[doc = "bar"]
const B = 0b00000010;
const C = 0b00000100;
#[doc = "foo"]
const ABC = A.bits | B.bits | C.bits;
}
}
#[test]
fn smoke() {
assert_eq!(ABC, A | B | C);
}

Просмотреть файл

@ -1,22 +0,0 @@
#![allow(dead_code)]
#![no_std]
#[macro_use]
extern crate bitflags;
bitflags! {
/// baz
struct Flags: u32 {
const A = 0b00000001;
#[doc = "bar"]
const B = 0b00000010;
const C = 0b00000100;
#[doc = "foo"]
const ABC = A.bits | B.bits | C.bits;
}
}
#[test]
fn smoke() {
assert_eq!(ABC, A | B | C);
}

Просмотреть файл

@ -1,30 +0,0 @@
#![cfg(feature = "unstable_testing")]
#![allow(dead_code, unused_imports)]
#![feature(i128_type)]
#[macro_use]
extern crate bitflags;
bitflags! {
/// baz
struct Flags128: u128 {
const A = 0x0000_0000_0000_0000_0000_0000_0000_0001;
const B = 0x0000_0000_0000_1000_0000_0000_0000_0000;
const C = 0x8000_0000_0000_0000_0000_0000_0000_0000;
const ABC = A.bits | B.bits | C.bits;
}
}
#[test]
fn test_i128_bitflags() {
assert_eq!(ABC, A | B | C);
assert_eq!(A.bits, 0x0000_0000_0000_0000_0000_0000_0000_0001);
assert_eq!(B.bits, 0x0000_0000_0000_1000_0000_0000_0000_0000);
assert_eq!(C.bits, 0x8000_0000_0000_0000_0000_0000_0000_0000);
assert_eq!(ABC.bits, 0x8000_0000_0000_1000_0000_0000_0000_0001);
assert_eq!(format!("{:?}", A), "A");
assert_eq!(format!("{:?}", B), "B");
assert_eq!(format!("{:?}", C), "C");
assert_eq!(format!("{:?}", ABC), "A | B | C | ABC");
}

Просмотреть файл

@ -1 +1 @@
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"d0da6f63d93a5cfb6536e3be8714239386a79fbfdfe3e6ec92a78c8ddde62010","Cargo.toml":"5a87b6a8e0411a560659a73163f9a222b4b6fa46c6d3ef7bb4dc1e5152807b4a","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"aedcbbbefde11d7d8df61645aa93324695e7035d847e934a92e0250920287072","src/example_generated.rs":"8e8f188edaaefb8cc75064bd9e6dfdb8d776132ad838cff377a1acf08216186f","src/lib.rs":"d66cedd360642fcaf89a84408ea6b336f9d89948800e0a8149465cc3a022a621","tests/conflicting_trait_impls.rs":"a2a2e28dee83ead220bbc76653ae203242d9024e05aa47217049c91dd66e3b91","tests/external.rs":"1ec3fb8681056383397f34a9ae87c3d24f031715f88602cab19fa3c820e021b0","tests/external_no_std.rs":"75e0e2d6257b67d4ab9d975a9851f0a874ca7d2cdb0940df6212eafbb0fc2d88","tests/i128_bitflags.rs":"e55fbd7529839bffb8e3a8bf00516b7aca9f4a51cfda5177da17aece8328ad55"},"package":"f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989"}
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".travis.yml":"e7a77c1800f9852e4c9a2acb9df041773ecd0bc005bd1b0657ae0512c67100ac","Cargo.toml":"f35826eec96c765ae8aee4f8a66c6b3cb0d918b49935baf05bae79b6df8e1077","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"602c63819e332e93c85dc8426db4855f18fe0fabbd642c5b2303ed83f1ba926f","src/example_generated.rs":"161b69d92cf6e5fa4b5dc30f06031f3a0fb590b44be2bcf0f31cb8be4fab36fa","src/lib.rs":"56e86a16356d9322fa6b4e9b910041e2e7558c08b52ffbdacc647eba36b37abc","tests/conflicting_trait_impls.rs":"79993ea67ef09a5f99fddd69d8b73b1c137e41d0e8f8535f03865d6766dcc498","tests/external.rs":"15f7901698e286197666ccd309ad1debd3c35eaff680ca090368494e8b06ccf2","tests/external_no_std.rs":"c3556fd19dd91d1b093eb6a65d09a9d0985544f0377ba3d30c0e265c956f7237","tests/i128_bitflags.rs":"c955ef2c9fd385848195bb416e660e946ccbe59acc87862ef2646eb082d82e3f"},"package":"4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"}

2
third_party/rust/bitflags/.travis.yml поставляемый
Просмотреть файл

@ -3,8 +3,6 @@ os:
- osx
language: rust
rust:
# This version is tested to avoid unintentional bumping of the minimum supported Rust version
- 1.20.0
- stable
- beta
- nightly

4
third_party/rust/bitflags/Cargo.toml поставляемый
Просмотреть файл

@ -12,7 +12,7 @@
[package]
name = "bitflags"
version = "1.0.0"
version = "0.9.1"
authors = ["The Rust Project Developers"]
description = "A macro to generate structures which behave like bitflags.\n"
homepage = "https://github.com/rust-lang-nursery/bitflags"
@ -24,8 +24,8 @@ license = "MIT/Apache-2.0"
repository = "https://github.com/rust-lang-nursery/bitflags"
[features]
example_generated = []
unstable_testing = []
default = ["example_generated"]
example_generated = []
[badges.travis-ci]
repository = "rust-lang-nursery/bitflags"

11
third_party/rust/bitflags/README.md поставляемый
Просмотреть файл

@ -5,8 +5,7 @@ A Rust macro to generate structures which behave like a set of bitflags
[![Build Status](https://travis-ci.org/rust-lang-nursery/bitflags.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/bitflags)
- [Documentation](https://docs.rs/bitflags)
- [Release notes](https://github.com/rust-lang-nursery/bitflags/releases)
[Documentation](https://docs.rs/bitflags)
## Usage
@ -14,7 +13,7 @@ Add this to your `Cargo.toml`:
```toml
[dependencies]
bitflags = "1.0"
bitflags = "0.9"
```
and this to your crate root:
@ -23,9 +22,3 @@ and this to your crate root:
#[macro_use]
extern crate bitflags;
```
## Rust Version Support
The minimum supported* Rust version is 1.20 due to use of associated constants.
_* As of the current master branch (unreleased)_

Просмотреть файл

@ -9,8 +9,8 @@ bitflags! {
const FLAG_A = 0b00000001;
const FLAG_B = 0b00000010;
const FLAG_C = 0b00000100;
const FLAG_ABC = Self::FLAG_A.bits
| Self::FLAG_B.bits
| Self::FLAG_C.bits;
const FLAG_ABC = FLAG_A.bits
| FLAG_B.bits
| FLAG_C.bits;
}
}

391
third_party/rust/bitflags/src/lib.rs поставляемый
Просмотреть файл

@ -26,19 +26,19 @@
//! const FLAG_A = 0b00000001;
//! const FLAG_B = 0b00000010;
//! const FLAG_C = 0b00000100;
//! const FLAG_ABC = Self::FLAG_A.bits
//! | Self::FLAG_B.bits
//! | Self::FLAG_C.bits;
//! const FLAG_ABC = FLAG_A.bits
//! | FLAG_B.bits
//! | FLAG_C.bits;
//! }
//! }
//!
//! fn main() {
//! let e1 = Flags::FLAG_A | Flags::FLAG_C;
//! let e2 = Flags::FLAG_B | Flags::FLAG_C;
//! assert_eq!((e1 | e2), Flags::FLAG_ABC); // union
//! assert_eq!((e1 & e2), Flags::FLAG_C); // intersection
//! assert_eq!((e1 - e2), Flags::FLAG_A); // set difference
//! assert_eq!(!e2, Flags::FLAG_A); // set complement
//! let e1 = FLAG_A | FLAG_C;
//! let e2 = FLAG_B | FLAG_C;
//! assert_eq!((e1 | e2), FLAG_ABC); // union
//! assert_eq!((e1 & e2), FLAG_C); // intersection
//! assert_eq!((e1 - e2), FLAG_A); // set difference
//! assert_eq!(!e2, FLAG_A); // set complement
//! }
//! ```
//!
@ -75,12 +75,12 @@
//! }
//!
//! fn main() {
//! let mut flags = Flags::FLAG_A | Flags::FLAG_B;
//! let mut flags = FLAG_A | FLAG_B;
//! flags.clear();
//! assert!(flags.is_empty());
//! assert_eq!(format!("{}", flags), "hi!");
//! assert_eq!(format!("{:?}", Flags::FLAG_A | Flags::FLAG_B), "FLAG_A | FLAG_B");
//! assert_eq!(format!("{:?}", Flags::FLAG_B), "FLAG_B");
//! assert_eq!(format!("{:?}", FLAG_A | FLAG_B), "FLAG_A | FLAG_B");
//! assert_eq!(format!("{:?}", FLAG_B), "FLAG_B");
//! }
//! ```
//!
@ -108,8 +108,8 @@
//! }
//!
//! fn main() {
//! let flag1 = example::Flags1::FLAG_A;
//! let flag2 = example::Flags2::FLAG_B; // error: const `FLAG_B` is private
//! let flag1 = example::FLAG_A;
//! let flag2 = example::FLAG_B; // error: const `FLAG_B` is private
//! }
//! ```
//!
@ -161,7 +161,6 @@
//! - `remove`: removes the specified flags in-place
//! - `toggle`: the specified flags will be inserted if not present, and removed
//! if they are.
//! - `set`: inserts or removes the specified flags depending on the passed value
//!
//! ## Default
//!
@ -207,19 +206,19 @@
//! // explicit `Default` implementation
//! impl Default for Flags {
//! fn default() -> Flags {
//! Flags::FLAG_A | Flags::FLAG_C
//! FLAG_A | FLAG_C
//! }
//! }
//!
//! fn main() {
//! let implemented_default: Flags = Default::default();
//! assert_eq!(implemented_default, (Flags::FLAG_A | Flags::FLAG_C));
//! assert_eq!(implemented_default, (FLAG_A | FLAG_C));
//! }
//! ```
#![no_std]
#![doc(html_root_url = "https://docs.rs/bitflags/1.0.0")]
#![doc(html_root_url = "https://docs.rs/bitflags/0.9.1")]
// When compiled for the rustc compiler itself we want to make sure that this is
// an unstable crate.
#![cfg_attr(rustbuild, feature(staged_api))]
@ -249,19 +248,19 @@ pub extern crate core as _core;
/// const FLAG_A = 0b00000001;
/// const FLAG_B = 0b00000010;
/// const FLAG_C = 0b00000100;
/// const FLAG_ABC = Self::FLAG_A.bits
/// | Self::FLAG_B.bits
/// | Self::FLAG_C.bits;
/// const FLAG_ABC = FLAG_A.bits
/// | FLAG_B.bits
/// | FLAG_C.bits;
/// }
/// }
///
/// fn main() {
/// let e1 = Flags::FLAG_A | Flags::FLAG_C;
/// let e2 = Flags::FLAG_B | Flags::FLAG_C;
/// assert_eq!((e1 | e2), Flags::FLAG_ABC); // union
/// assert_eq!((e1 & e2), Flags::FLAG_C); // intersection
/// assert_eq!((e1 - e2), Flags::FLAG_A); // set difference
/// assert_eq!(!e2, Flags::FLAG_A); // set complement
/// let e1 = FLAG_A | FLAG_C;
/// let e2 = FLAG_B | FLAG_C;
/// assert_eq!((e1 | e2), FLAG_ABC); // union
/// assert_eq!((e1 & e2), FLAG_C); // intersection
/// assert_eq!((e1 - e2), FLAG_A); // set difference
/// assert_eq!(!e2, FLAG_A); // set complement
/// }
/// ```
///
@ -295,77 +294,59 @@ pub extern crate core as _core;
/// }
///
/// fn main() {
/// let mut flags = Flags::FLAG_A | Flags::FLAG_B;
/// let mut flags = FLAG_A | FLAG_B;
/// flags.clear();
/// assert!(flags.is_empty());
/// assert_eq!(format!("{}", flags), "hi!");
/// assert_eq!(format!("{:?}", Flags::FLAG_A | Flags::FLAG_B), "FLAG_A | FLAG_B");
/// assert_eq!(format!("{:?}", Flags::FLAG_B), "FLAG_B");
/// assert_eq!(format!("{:?}", FLAG_A | FLAG_B), "FLAG_A | FLAG_B");
/// assert_eq!(format!("{:?}", FLAG_B), "FLAG_B");
/// }
/// ```
#[macro_export]
macro_rules! bitflags {
(
$(#[$outer:meta])*
pub struct $BitFlags:ident: $T:ty {
$(
$(#[$inner:ident $($args:tt)*])*
const $Flag:ident = $value:expr;
)+
}
) => {
($(#[$attr:meta])* pub struct $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
}) => {
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
$(#[$outer])*
$(#[$attr])*
pub struct $BitFlags {
bits: $T,
}
$($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: $value };)+
__impl_bitflags! {
struct $BitFlags: $T {
$(
$(#[$inner $($args)*])*
const $Flag = $value;
)+
$($(#[$Flag_attr])* const $Flag = $value;)+
}
}
};
(
$(#[$outer:meta])*
struct $BitFlags:ident: $T:ty {
$(
$(#[$inner:ident $($args:tt)*])*
const $Flag:ident = $value:expr;
)+
}
) => {
($(#[$attr:meta])* struct $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
}) => {
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
$(#[$outer])*
$(#[$attr])*
struct $BitFlags {
bits: $T,
}
$($(#[$Flag_attr])* const $Flag: $BitFlags = $BitFlags { bits: $value };)+
__impl_bitflags! {
struct $BitFlags: $T {
$(
$(#[$inner $($args)*])*
const $Flag = $value;
)+
$($(#[$Flag_attr])* const $Flag = $value;)+
}
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __impl_bitflags {
(
struct $BitFlags:ident: $T:ty {
$(
$(#[$attr:ident $($args:tt)*])*
const $Flag:ident = $value:expr;
)+
}
) => {
(struct $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
}) => {
impl $crate::_core::fmt::Debug for $BitFlags {
fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
// This convoluted approach is to handle #[cfg]-based flag
@ -387,12 +368,9 @@ macro_rules! __impl_bitflags {
// are not #[cfg]ed away.
impl __BitFlags for $BitFlags {
$(
__impl_bitflags! {
#[allow(deprecated)]
$(? #[$attr $($args)*])*
fn $Flag(&self) -> bool {
self.bits & Self::$Flag.bits == Self::$Flag.bits
}
$(#[$Flag_attr])*
fn $Flag(&self) -> bool {
self.bits & $Flag.bits == $Flag.bits
}
)+
}
@ -436,11 +414,6 @@ macro_rules! __impl_bitflags {
#[allow(dead_code)]
impl $BitFlags {
$(
$(#[$attr $($args)*])*
pub const $Flag: $BitFlags = $BitFlags { bits: $value };
)+
/// Returns an empty set of flags.
#[inline]
pub fn empty() -> $BitFlags {
@ -459,11 +432,8 @@ macro_rules! __impl_bitflags {
}
impl __BitFlags for $BitFlags {
$(
__impl_bitflags! {
#[allow(deprecated)]
$(? #[$attr $($args)*])*
fn $Flag() -> $T { Self::$Flag.bits }
}
$(#[$Flag_attr])*
fn $Flag() -> $T { $Flag.bits }
)+
}
$BitFlags { bits: $(<$BitFlags as __BitFlags>::$Flag())|+ }
@ -648,65 +618,13 @@ macro_rules! __impl_bitflags {
}
}
};
// Every attribute that the user writes on a const is applied to the
// corresponding const that we generate, but within the implementation of
// Debug and all() we want to ignore everything but #[cfg] attributes. In
// particular, including a #[deprecated] attribute on those items would fail
// to compile.
// https://github.com/rust-lang-nursery/bitflags/issues/109
//
// Input:
//
// ? #[cfg(feature = "advanced")]
// ? #[deprecated(note = "Use somthing else.")]
// ? #[doc = r"High quality documentation."]
// fn f() -> i32 { /* ... */ }
//
// Output:
//
// #[cfg(feature = "advanced")]
// fn f() -> i32 { /* ... */ }
(
$(#[$filtered:meta])*
? #[cfg $($cfgargs:tt)*]
$(? #[$rest:ident $($restargs:tt)*])*
fn $($item:tt)*
) => {
__impl_bitflags! {
$(#[$filtered])*
#[cfg $($cfgargs)*]
$(? #[$rest $($restargs)*])*
fn $($item)*
}
};
(
$(#[$filtered:meta])*
// $next != `cfg`
? #[$next:ident $($nextargs:tt)*]
$(? #[$rest:ident $($restargs:tt)*])*
fn $($item:tt)*
) => {
__impl_bitflags! {
$(#[$filtered])*
// $next filtered out
$(? #[$rest $($restargs)*])*
fn $($item)*
}
};
(
$(#[$filtered:meta])*
fn $($item:tt)*
) => {
$(#[$filtered])*
fn $($item)*
};
}
#[cfg(feature = "example_generated")]
pub mod example_generated;
#[cfg(test)]
#[allow(non_upper_case_globals, dead_code)]
mod tests {
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
@ -717,71 +635,71 @@ mod tests {
#[doc = "> "]
#[doc = "> - Richard Feynman"]
struct Flags: u32 {
const FLAG_A = 0b00000001;
const FlagA = 0b00000001;
#[doc = "<pcwalton> macros are way better at generating code than trans is"]
const FLAG_B = 0b00000010;
const FLAG_C = 0b00000100;
const FlagB = 0b00000010;
const FlagC = 0b00000100;
#[doc = "* cmr bed"]
#[doc = "* strcat table"]
#[doc = "<strcat> wait what?"]
const FLAG_ABC = Self::FLAG_A.bits
| Self::FLAG_B.bits
| Self::FLAG_C.bits;
const FlagABC = FlagA.bits
| FlagB.bits
| FlagC.bits;
}
}
bitflags! {
struct _CfgFlags: u32 {
#[cfg(windows)]
const _CFG_A = 0b01;
const _CfgA = 0b01;
#[cfg(unix)]
const _CFG_B = 0b01;
const _CfgB = 0b01;
#[cfg(windows)]
const _CFG_C = _CFG_A.bits | 0b10;
const _CfgC = _CfgA.bits | 0b10;
}
}
bitflags! {
struct AnotherSetOfFlags: i8 {
const ANOTHER_FLAG = -1_i8;
const AnotherFlag = -1_i8;
}
}
bitflags! {
struct LongFlags: u32 {
const LONG_FLAG_A = 0b1111111111111111;
const LongFlagA = 0b1111111111111111;
}
}
#[test]
fn test_bits(){
assert_eq!(Flags::empty().bits(), 0b00000000);
assert_eq!(Flags::FLAG_A.bits(), 0b00000001);
assert_eq!(Flags::FLAG_ABC.bits(), 0b00000111);
assert_eq!(FlagA.bits(), 0b00000001);
assert_eq!(FlagABC.bits(), 0b00000111);
assert_eq!(AnotherSetOfFlags::empty().bits(), 0b00);
assert_eq!(AnotherSetOfFlags::ANOTHER_FLAG.bits(), !0_i8);
assert_eq!(AnotherFlag.bits(), !0_i8);
}
#[test]
fn test_from_bits() {
assert_eq!(Flags::from_bits(0), Some(Flags::empty()));
assert_eq!(Flags::from_bits(0b1), Some(Flags::FLAG_A));
assert_eq!(Flags::from_bits(0b10), Some(Flags::FLAG_B));
assert_eq!(Flags::from_bits(0b11), Some(Flags::FLAG_A | Flags::FLAG_B));
assert_eq!(Flags::from_bits(0b1), Some(FlagA));
assert_eq!(Flags::from_bits(0b10), Some(FlagB));
assert_eq!(Flags::from_bits(0b11), Some(FlagA | FlagB));
assert_eq!(Flags::from_bits(0b1000), None);
assert_eq!(AnotherSetOfFlags::from_bits(!0_i8), Some(AnotherSetOfFlags::ANOTHER_FLAG));
assert_eq!(AnotherSetOfFlags::from_bits(!0_i8), Some(AnotherFlag));
}
#[test]
fn test_from_bits_truncate() {
assert_eq!(Flags::from_bits_truncate(0), Flags::empty());
assert_eq!(Flags::from_bits_truncate(0b1), Flags::FLAG_A);
assert_eq!(Flags::from_bits_truncate(0b10), Flags::FLAG_B);
assert_eq!(Flags::from_bits_truncate(0b11), (Flags::FLAG_A | Flags::FLAG_B));
assert_eq!(Flags::from_bits_truncate(0b1), FlagA);
assert_eq!(Flags::from_bits_truncate(0b10), FlagB);
assert_eq!(Flags::from_bits_truncate(0b11), (FlagA | FlagB));
assert_eq!(Flags::from_bits_truncate(0b1000), Flags::empty());
assert_eq!(Flags::from_bits_truncate(0b1001), Flags::FLAG_A);
assert_eq!(Flags::from_bits_truncate(0b1001), FlagA);
assert_eq!(AnotherSetOfFlags::from_bits_truncate(0_i8), AnotherSetOfFlags::empty());
}
@ -789,19 +707,19 @@ mod tests {
#[test]
fn test_is_empty(){
assert!(Flags::empty().is_empty());
assert!(!Flags::FLAG_A.is_empty());
assert!(!Flags::FLAG_ABC.is_empty());
assert!(!FlagA.is_empty());
assert!(!FlagABC.is_empty());
assert!(!AnotherSetOfFlags::ANOTHER_FLAG.is_empty());
assert!(!AnotherFlag.is_empty());
}
#[test]
fn test_is_all() {
assert!(Flags::all().is_all());
assert!(!Flags::FLAG_A.is_all());
assert!(Flags::FLAG_ABC.is_all());
assert!(!FlagA.is_all());
assert!(FlagABC.is_all());
assert!(AnotherSetOfFlags::ANOTHER_FLAG.is_all());
assert!(AnotherFlag.is_all());
}
#[test]
@ -810,77 +728,77 @@ mod tests {
let e2 = Flags::empty();
assert!(!e1.intersects(e2));
assert!(AnotherSetOfFlags::ANOTHER_FLAG.intersects(AnotherSetOfFlags::ANOTHER_FLAG));
assert!(AnotherFlag.intersects(AnotherFlag));
}
#[test]
fn test_empty_does_not_intersect_with_full() {
let e1 = Flags::empty();
let e2 = Flags::FLAG_ABC;
let e2 = FlagABC;
assert!(!e1.intersects(e2));
}
#[test]
fn test_disjoint_intersects() {
let e1 = Flags::FLAG_A;
let e2 = Flags::FLAG_B;
let e1 = FlagA;
let e2 = FlagB;
assert!(!e1.intersects(e2));
}
#[test]
fn test_overlapping_intersects() {
let e1 = Flags::FLAG_A;
let e2 = Flags::FLAG_A | Flags::FLAG_B;
let e1 = FlagA;
let e2 = FlagA | FlagB;
assert!(e1.intersects(e2));
}
#[test]
fn test_contains() {
let e1 = Flags::FLAG_A;
let e2 = Flags::FLAG_A | Flags::FLAG_B;
let e1 = FlagA;
let e2 = FlagA | FlagB;
assert!(!e1.contains(e2));
assert!(e2.contains(e1));
assert!(Flags::FLAG_ABC.contains(e2));
assert!(FlagABC.contains(e2));
assert!(AnotherSetOfFlags::ANOTHER_FLAG.contains(AnotherSetOfFlags::ANOTHER_FLAG));
assert!(AnotherFlag.contains(AnotherFlag));
}
#[test]
fn test_insert(){
let mut e1 = Flags::FLAG_A;
let e2 = Flags::FLAG_A | Flags::FLAG_B;
let mut e1 = FlagA;
let e2 = FlagA | FlagB;
e1.insert(e2);
assert_eq!(e1, e2);
let mut e3 = AnotherSetOfFlags::empty();
e3.insert(AnotherSetOfFlags::ANOTHER_FLAG);
assert_eq!(e3, AnotherSetOfFlags::ANOTHER_FLAG);
e3.insert(AnotherFlag);
assert_eq!(e3, AnotherFlag);
}
#[test]
fn test_remove(){
let mut e1 = Flags::FLAG_A | Flags::FLAG_B;
let e2 = Flags::FLAG_A | Flags::FLAG_C;
let mut e1 = FlagA | FlagB;
let e2 = FlagA | FlagC;
e1.remove(e2);
assert_eq!(e1, Flags::FLAG_B);
assert_eq!(e1, FlagB);
let mut e3 = AnotherSetOfFlags::ANOTHER_FLAG;
e3.remove(AnotherSetOfFlags::ANOTHER_FLAG);
let mut e3 = AnotherFlag;
e3.remove(AnotherFlag);
assert_eq!(e3, AnotherSetOfFlags::empty());
}
#[test]
fn test_operators() {
let e1 = Flags::FLAG_A | Flags::FLAG_C;
let e2 = Flags::FLAG_B | Flags::FLAG_C;
assert_eq!((e1 | e2), Flags::FLAG_ABC); // union
assert_eq!((e1 & e2), Flags::FLAG_C); // intersection
assert_eq!((e1 - e2), Flags::FLAG_A); // set difference
assert_eq!(!e2, Flags::FLAG_A); // set complement
assert_eq!(e1 ^ e2, Flags::FLAG_A | Flags::FLAG_B); // toggle
let e1 = FlagA | FlagC;
let e2 = FlagB | FlagC;
assert_eq!((e1 | e2), FlagABC); // union
assert_eq!((e1 & e2), FlagC); // intersection
assert_eq!((e1 - e2), FlagA); // set difference
assert_eq!(!e2, FlagA); // set complement
assert_eq!(e1 ^ e2, FlagA | FlagB); // toggle
let mut e3 = e1;
e3.toggle(e2);
assert_eq!(e3, Flags::FLAG_A | Flags::FLAG_B);
assert_eq!(e3, FlagA | FlagB);
let mut m4 = AnotherSetOfFlags::empty();
m4.toggle(AnotherSetOfFlags::empty());
@ -889,23 +807,23 @@ mod tests {
#[test]
fn test_set() {
let mut e1 = Flags::FLAG_A | Flags::FLAG_C;
e1.set(Flags::FLAG_B, true);
e1.set(Flags::FLAG_C, false);
let mut e1 = FlagA | FlagC;
e1.set(FlagB, true);
e1.set(FlagC, false);
assert_eq!(e1, Flags::FLAG_A | Flags::FLAG_B);
assert_eq!(e1, FlagA | FlagB);
}
#[test]
fn test_assignment_operators() {
let mut m1 = Flags::empty();
let e1 = Flags::FLAG_A | Flags::FLAG_C;
let e1 = FlagA | FlagC;
// union
m1 |= Flags::FLAG_A;
assert_eq!(m1, Flags::FLAG_A);
m1 |= FlagA;
assert_eq!(m1, FlagA);
// intersection
m1 &= e1;
assert_eq!(m1, Flags::FLAG_A);
assert_eq!(m1, FlagA);
// set difference
m1 -= m1;
assert_eq!(m1, Flags::empty());
@ -923,25 +841,23 @@ mod tests {
assert_eq!(flags, Flags::empty());
flags = Flags::empty();
flags.extend([Flags::FLAG_A, Flags::FLAG_B].iter().cloned());
assert_eq!(flags, Flags::FLAG_A | Flags::FLAG_B);
flags.extend([FlagA, FlagB].iter().cloned());
assert_eq!(flags, FlagA | FlagB);
flags = Flags::FLAG_A;
flags.extend([Flags::FLAG_A, Flags::FLAG_B].iter().cloned());
assert_eq!(flags, Flags::FLAG_A | Flags::FLAG_B);
flags = FlagA;
flags.extend([FlagA, FlagB].iter().cloned());
assert_eq!(flags, FlagA | FlagB);
flags = Flags::FLAG_B;
flags.extend([Flags::FLAG_A, Flags::FLAG_ABC].iter().cloned());
assert_eq!(flags, Flags::FLAG_ABC);
flags = FlagB;
flags.extend([FlagA, FlagABC].iter().cloned());
assert_eq!(flags, FlagABC);
}
#[test]
fn test_from_iterator() {
assert_eq!([].iter().cloned().collect::<Flags>(), Flags::empty());
assert_eq!([Flags::FLAG_A, Flags::FLAG_B].iter().cloned().collect::<Flags>(),
Flags::FLAG_A | Flags::FLAG_B);
assert_eq!([Flags::FLAG_A, Flags::FLAG_ABC].iter().cloned().collect::<Flags>(),
Flags::FLAG_ABC);
assert_eq!([FlagA, FlagB].iter().cloned().collect::<Flags>(), FlagA | FlagB);
assert_eq!([FlagA, FlagABC].iter().cloned().collect::<Flags>(), FlagABC);
}
#[test]
@ -950,11 +866,11 @@ mod tests {
let mut b = Flags::empty();
assert!(!(a < b) && !(b < a));
b = Flags::FLAG_B;
b = FlagB;
assert!(a < b);
a = Flags::FLAG_C;
a = FlagC;
assert!(!(a < b) && b < a);
b = Flags::FLAG_C | Flags::FLAG_B;
b = FlagC | FlagB;
assert!(a < b);
}
@ -964,10 +880,10 @@ mod tests {
let mut b = Flags::empty();
assert!(a <= b && a >= b);
a = Flags::FLAG_A;
a = FlagA;
assert!(a > b && a >= b);
assert!(b < a && b <= a);
b = Flags::FLAG_B;
b = FlagB;
assert!(b > a && b >= a);
assert!(a < b && a <= b);
}
@ -984,63 +900,62 @@ mod tests {
let mut y = Flags::empty();
assert_eq!(hash(&x), hash(&y));
x = Flags::all();
y = Flags::FLAG_ABC;
y = FlagABC;
assert_eq!(hash(&x), hash(&y));
}
#[test]
fn test_debug() {
assert_eq!(format!("{:?}", Flags::FLAG_A | Flags::FLAG_B), "FLAG_A | FLAG_B");
assert_eq!(format!("{:?}", FlagA | FlagB), "FlagA | FlagB");
assert_eq!(format!("{:?}", Flags::empty()), "(empty)");
assert_eq!(format!("{:?}", Flags::FLAG_ABC), "FLAG_A | FLAG_B | FLAG_C | FLAG_ABC");
assert_eq!(format!("{:?}", FlagABC), "FlagA | FlagB | FlagC | FlagABC");
}
#[test]
fn test_binary() {
assert_eq!(format!("{:b}", Flags::FLAG_ABC), "111");
assert_eq!(format!("{:#b}", Flags::FLAG_ABC), "0b111");
assert_eq!(format!("{:b}", FlagABC), "111");
assert_eq!(format!("{:#b}", FlagABC), "0b111");
}
#[test]
fn test_octal() {
assert_eq!(format!("{:o}", LongFlags::LONG_FLAG_A), "177777");
assert_eq!(format!("{:#o}", LongFlags::LONG_FLAG_A), "0o177777");
assert_eq!(format!("{:o}", LongFlagA), "177777");
assert_eq!(format!("{:#o}", LongFlagA), "0o177777");
}
#[test]
fn test_lowerhex() {
assert_eq!(format!("{:x}", LongFlags::LONG_FLAG_A), "ffff");
assert_eq!(format!("{:#x}", LongFlags::LONG_FLAG_A), "0xffff");
assert_eq!(format!("{:x}", LongFlagA), "ffff");
assert_eq!(format!("{:#x}", LongFlagA), "0xffff");
}
#[test]
fn test_upperhex() {
assert_eq!(format!("{:X}", LongFlags::LONG_FLAG_A), "FFFF");
assert_eq!(format!("{:#X}", LongFlags::LONG_FLAG_A), "0xFFFF");
assert_eq!(format!("{:X}", LongFlagA), "FFFF");
assert_eq!(format!("{:#X}", LongFlagA), "0xFFFF");
}
mod submodule {
bitflags! {
pub struct PublicFlags: i8 {
const FLAG_X = 0;
const FlagX = 0;
}
}
bitflags! {
struct PrivateFlags: i8 {
const FLAG_Y = 0;
const FlagY = 0;
}
}
#[test]
fn test_private() {
let _ = PrivateFlags::FLAG_Y;
let _ = FlagY;
}
}
#[test]
fn test_public() {
let _ = submodule::PublicFlags::FLAG_X;
let _ = submodule::FlagX;
}
mod t1 {
@ -1069,17 +984,7 @@ mod tests {
const B = 2;
}
}
assert_eq!(Flags::all(), Flags::A);
assert_eq!(format!("{:?}", Flags::A), "A");
}
#[test]
fn test_deprecated() {
bitflags! {
pub struct TestFlags: u32 {
#[deprecated(note = "Use something else.")]
const FLAG_ONE = 1;
}
}
assert_eq!(Flags::all(), A);
assert_eq!(format!("{:?}", A), "A");
}
}

Просмотреть файл

@ -1,3 +1,4 @@
#![allow(dead_code)]
#![no_std]
#[macro_use]

6
third_party/rust/bitflags/tests/external.rs поставляемый
Просмотреть файл

@ -1,3 +1,5 @@
#![allow(dead_code)]
#[macro_use]
extern crate bitflags;
@ -9,11 +11,11 @@ bitflags! {
const B = 0b00000010;
const C = 0b00000100;
#[doc = "foo"]
const ABC = Flags::A.bits | Flags::B.bits | Flags::C.bits;
const ABC = A.bits | B.bits | C.bits;
}
}
#[test]
fn smoke() {
assert_eq!(Flags::ABC, Flags::A | Flags::B | Flags::C);
assert_eq!(ABC, A | B | C);
}

Просмотреть файл

@ -1,3 +1,4 @@
#![allow(dead_code)]
#![no_std]
#[macro_use]
@ -11,11 +12,11 @@ bitflags! {
const B = 0b00000010;
const C = 0b00000100;
#[doc = "foo"]
const ABC = Flags::A.bits | Flags::B.bits | Flags::C.bits;
const ABC = A.bits | B.bits | C.bits;
}
}
#[test]
fn smoke() {
assert_eq!(Flags::ABC, Flags::A | Flags::B | Flags::C);
assert_eq!(ABC, A | B | C);
}

Просмотреть файл

@ -1,5 +1,6 @@
#![cfg(feature = "unstable_testing")]
#![allow(dead_code, unused_imports)]
#![feature(i128_type)]
#[macro_use]
@ -11,19 +12,19 @@ bitflags! {
const A = 0x0000_0000_0000_0000_0000_0000_0000_0001;
const B = 0x0000_0000_0000_1000_0000_0000_0000_0000;
const C = 0x8000_0000_0000_0000_0000_0000_0000_0000;
const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
const ABC = A.bits | B.bits | C.bits;
}
}
#[test]
fn test_i128_bitflags() {
assert_eq!(Flags128::ABC, Flags128::A | Flags128::B | Flags128::C);
assert_eq!(Flags128::A.bits, 0x0000_0000_0000_0000_0000_0000_0000_0001);
assert_eq!(Flags128::B.bits, 0x0000_0000_0000_1000_0000_0000_0000_0000);
assert_eq!(Flags128::C.bits, 0x8000_0000_0000_0000_0000_0000_0000_0000);
assert_eq!(Flags128::ABC.bits, 0x8000_0000_0000_1000_0000_0000_0000_0001);
assert_eq!(format!("{:?}", Flags128::A), "A");
assert_eq!(format!("{:?}", Flags128::B), "B");
assert_eq!(format!("{:?}", Flags128::C), "C");
assert_eq!(format!("{:?}", Flags128::ABC), "A | B | C | ABC");
assert_eq!(ABC, A | B | C);
assert_eq!(A.bits, 0x0000_0000_0000_0000_0000_0000_0000_0001);
assert_eq!(B.bits, 0x0000_0000_0000_1000_0000_0000_0000_0000);
assert_eq!(C.bits, 0x8000_0000_0000_0000_0000_0000_0000_0000);
assert_eq!(ABC.bits, 0x8000_0000_0000_1000_0000_0000_0000_0001);
assert_eq!(format!("{:?}", A), "A");
assert_eq!(format!("{:?}", B), "B");
assert_eq!(format!("{:?}", C), "C");
assert_eq!(format!("{:?}", ABC), "A | B | C | ABC");
}

10
toolkit/library/gtest/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -190,11 +190,6 @@ name = "bitflags"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitreader"
version = "0.3.0"
@ -1597,7 +1592,7 @@ version = "0.52.1"
dependencies = [
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1624,7 +1619,7 @@ version = "0.52.1"
dependencies = [
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1693,7 +1688,6 @@ dependencies = [
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989"
"checksum bitreader 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "80b13e2ab064ff3aa0bdbf1eff533f9822dc37899821f5f98c67f263eab51707"
"checksum boxfnonce 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8380105befe91099e6f69206164072c05bc92427ff6aa8a5171388317346dd75"
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"

10
toolkit/library/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -189,11 +189,6 @@ name = "bitflags"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitreader"
version = "0.3.0"
@ -1609,7 +1604,7 @@ version = "0.52.1"
dependencies = [
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1636,7 +1631,7 @@ version = "0.52.1"
dependencies = [
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1705,7 +1700,6 @@ dependencies = [
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989"
"checksum bitreader 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "80b13e2ab064ff3aa0bdbf1eff533f9822dc37899821f5f98c67f263eab51707"
"checksum boxfnonce 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8380105befe91099e6f69206164072c05bc92427ff6aa8a5171388317346dd75"
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"