Skip to main content

ferrijs_std/utils/
io.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4macro_rules! define_extension {
5    ($base:ident, $file:ident, $ext:expr) => {
6        #[allow(dead_code)]
7        pub const $base: &str = $ext;
8        #[allow(dead_code)]
9        pub const $file: &str = concat!(".", $ext);
10    };
11}
12
13define_extension!(BYTECODE_EXT, BYTECODE_FILE_EXT, "lrt");
14
15macro_rules! define_supported_extensions {
16    // Accepts a list of supported extensions and a single additional constant extension
17    ($constant_ext:ident, $($ext:literal),*) => {
18        // Define the array of extensions as a constant
19        pub const SUPPORTED_EXTENSIONS: &[&str] = &[$($ext),*, $constant_ext];
20
21        pub const JS_EXTENSIONS: &[&str] = &[$($ext),*];
22
23        // Define the function `is_supported_ext` using a match statement
24        pub fn is_supported_ext(ext: &str) -> bool {
25            matches!(ext, $($ext)|* | $constant_ext)
26        }
27    };
28}
29
30define_supported_extensions!(BYTECODE_FILE_EXT, ".js", ".mjs", ".cjs");