brk_rolldown_common/inner_bundler_options/types/
platform.rs

1#[cfg(feature = "deserialize_bundler_options")]
2use schemars::JsonSchema;
3#[cfg(feature = "deserialize_bundler_options")]
4use serde::Deserialize;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[cfg_attr(feature = "deserialize_bundler_options", derive(Deserialize, JsonSchema))]
8#[cfg_attr(feature = "deserialize_bundler_options", serde(rename_all = "camelCase"))]
9pub enum Platform {
10  /// Represents the Node.js platform.
11  Node,
12  Browser,
13  Neutral,
14}
15
16impl TryFrom<&str> for Platform {
17  type Error = String;
18
19  fn try_from(value: &str) -> Result<Self, Self::Error> {
20    match value {
21      "node" => Ok(Self::Node),
22      "browser" => Ok(Self::Browser),
23      "neutral" => Ok(Self::Neutral),
24      _ => Err(format!("Unknown platform: {value:?}")),
25    }
26  }
27}
28
29impl std::fmt::Display for Platform {
30  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31    match self {
32      Self::Node => write!(f, "node"),
33      Self::Browser => write!(f, "browser"),
34      Self::Neutral => write!(f, "neutral"),
35    }
36  }
37}