about summary refs log tree commit diff
path: root/library/stdarch/crates/std_detect/src/detect/mod.rs
diff options
context:
space:
mode:
authorgnzlbg <gonzalobg88@gmail.com>2019-04-23 15:51:20 +0200
committergnzlbg <gnzlbg@users.noreply.github.com>2019-09-16 23:43:01 +0200
commit1f44c1407dc6e6f91600f9303739ca8acbcc8194 (patch)
treefb4d4c554ce3aaceccc1ce679c33fc9003a259bc /library/stdarch/crates/std_detect/src/detect/mod.rs
parentf3140f4b25860a1aa6257c6afc064efe177b0b67 (diff)
downloadrust-1f44c1407dc6e6f91600f9303739ca8acbcc8194.tar.gz
rust-1f44c1407dc6e6f91600f9303739ca8acbcc8194.zip
Add std_detect::detect::features() -> impl Iterator<Item=(&'static str, bool)> API
Diffstat (limited to 'library/stdarch/crates/std_detect/src/detect/mod.rs')
-rw-r--r--library/stdarch/crates/std_detect/src/detect/mod.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/library/stdarch/crates/std_detect/src/detect/mod.rs b/library/stdarch/crates/std_detect/src/detect/mod.rs
index 3e00c205547..21062782b71 100644
--- a/library/stdarch/crates/std_detect/src/detect/mod.rs
+++ b/library/stdarch/crates/std_detect/src/detect/mod.rs
@@ -20,6 +20,9 @@
 #[macro_use]
 mod error_macros;
 
+#[macro_use]
+mod macros;
+
 cfg_if! {
     if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
         #[path = "arch/x86.rs"]
@@ -96,3 +99,36 @@ cfg_if! {
 pub fn check_for(x: Feature) -> bool {
     cache::test(x as u32, self::os::detect_features)
 }
+
+/// Returns an `Iterator<Item=(&'static str, bool)>` where
+/// `Item.0` is the feature name, and `Item.1` is a `bool` which
+/// is `true` if the feature is supported by the host and `false` otherwise.
+#[unstable(feature = "stdsimd", issue = "27731")]
+pub fn features() -> impl Iterator<Item = (&'static str, bool)> {
+    cfg_if! {
+        if #[cfg(any(
+            target_arch = "x86",
+            target_arch = "x86_64",
+            target_arch = "arm",
+            target_arch = "aarch64",
+            target_arch = "powerpc",
+            target_arch = "powerpc64",
+            target_arch = "mips",
+            target_arch = "mips64",
+        ))] {
+            fn impl_() -> impl Iterator<Item=(&'static str, bool)> {
+                (0_u8..Feature::_last as u8).map(|discriminant: u8| {
+                    let f: Feature = unsafe { crate::mem::transmute(discriminant) };
+                    let name: &'static str = f.to_str();
+                    let enabled: bool = check_for(f);
+                    (name, enabled)
+                })
+            }
+        } else {
+            fn impl_() -> impl Iterator<Item=(&'static str, bool)> {
+                (0_u8..0_u8).map(|_x: u8| ("", false))
+            }
+        }
+    }
+    impl_()
+}