ferrijs-std 0.2.1

Node and web standard library for the ferrijs QuickJS runtime: WHATWG Streams, Events, AbortController, Buffer, crypto, fs, os, url, zlib and the capability model they enforce (partly derived from awslabs/llrt, Apache-2.0).
Documentation
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#[macro_export]
macro_rules! count_members {
    () => (0);
    ($head:tt $(,$tail:tt)*) => (1 + count_members!($($tail),*));
}

#[macro_export]
macro_rules! iterable_enum {
    ($name:ident, $($variant:ident),*) => {
        impl $name {
            const VARIANTS: &'static [$name] = &[$($name::$variant,)*];
            pub fn iter() -> std::slice::Iter<'static, $name> {
                Self::VARIANTS.iter()
            }

            #[allow(dead_code)]
            fn _ensure_all_variants(s: Self) {
                match s {
                    $($name::$variant => {},)*
                }
            }
        }
    };
}

#[macro_export]
macro_rules! str_enum {
    ($name:ident, $($variant:ident => $str:expr),*) => {
        impl $name {
            pub fn as_str(&self) -> &'static str {
                match self {
                    $($name::$variant => $str,)*
                }
            }
        }

        impl AsRef<str> for $name {
            fn as_ref(&self) -> &str {
                self.as_str()
            }
        }

        impl TryFrom<&str> for $name {
            type Error = String;
            fn try_from(s: &str) -> std::result::Result<Self, Self::Error> {
                match s {
                    $($str => Ok($name::$variant),)*
                    _ => Err(["'", s, "' not available"].concat())
                }
            }
        }
    };
}