testutils/os_cmd/presets/cargo_build/flags/
code_model.rs

1use crate::os_cmd::{MiniStr, presets::cargo_build::flags::try_into_mini_arg};
2
3#[derive(Debug, Clone)]
4/// rustc --print code-models
5///
6/// From the rustc book:
7///
8/// > Code models put constraints on address ranges that the program and its
9/// > symbols may use.
10/// >
11/// > With smaller address ranges machine instructions may be
12/// > able to use more compact addressing modes.
13pub enum CodeModel {
14  Tiny,
15  Small,
16  Kernel,
17  Medium,
18  Large,
19  Ignore,
20}
21
22impl From<&str> for CodeModel {
23  fn from(value: &str) -> Self {
24    use CodeModel::*;
25    match value {
26      "tiny" => Tiny,
27      "small" => Small,
28      "kernel" => Kernel,
29      "medium" => Medium,
30      "large" => Large,
31      _ => Ignore,
32    }
33  }
34}
35
36impl CodeModel {
37  /// Converts CodeModel as `&str`
38  pub const fn as_str(&self) -> &str {
39    use CodeModel::*;
40    match self {
41      Tiny => "tiny",
42      Small => "small",
43      Kernel => "kernel",
44      Medium => "medium",
45      Large => "large",
46      Ignore => "",
47    }
48  }
49}
50
51impl AsRef<str> for CodeModel {
52  fn as_ref(&self) -> &str {
53    self.as_str()
54  }
55}
56
57impl From<CodeModel> for Option<MiniStr> {
58  fn from(model: CodeModel) -> Self {
59    try_into_mini_arg("code-model", model)
60  }
61}
62
63impl Default for CodeModel {
64  /// Default: Ignore
65  fn default() -> Self {
66    Self::Ignore
67  }
68}