about summary refs log tree commit diff
path: root/src/libstd/bitflags.rs
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2014-05-02 10:41:07 -0700
committerAaron Turon <aturon@mozilla.com>2014-05-05 15:24:36 -0700
commitc00d8fd9a07244a13d1cc7162a80c3d618935ce8 (patch)
tree377273474798d8fae7931491ccddab89b81efd2c /src/libstd/bitflags.rs
parentb733df0fc7942aea205d8fc451d2a4d17d47dfe9 (diff)
Add (unsafe) coercion from bits to std::bitflags
The intent of `std::bitflags` is to allow building type-safe wrappers
around C-style flags APIs. But in addition to construction these flags
from the Rust side, we need a way to convert them from the C
side. This patch adds a `from_bits` function, which is unsafe since
the bits in question may not represent a valid combination of flags.
Diffstat (limited to 'src/libstd/bitflags.rs')
-rw-r--r--src/libstd/bitflags.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs
index 3c06682eaaf..5737bc772df 100644
--- a/src/libstd/bitflags.rs
+++ b/src/libstd/bitflags.rs
@@ -127,6 +127,12 @@ macro_rules! bitflags(
                 self.bits
             }
 
+            /// Convert from underlying bit representation. Unsafe because the
+            /// bits are not guaranteed to represent valid flags.
+            pub unsafe fn from_bits(bits: $T) -> $BitFlags {
+                $BitFlags { bits: bits }
+            }
+
             /// Returns `true` if no flags are currently stored.
             pub fn is_empty(&self) -> bool {
                 *self == $BitFlags::empty()