cargo_subcommand/
profile.rs1use crate::error::Error;
2use std::path::Path;
3
4#[derive(Clone, Debug, Eq, Hash, PartialEq)]
5pub enum Profile {
6 Dev,
7 Release,
8 Custom(String),
9}
10
11impl std::fmt::Display for Profile {
12 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
13 f.write_str(match self {
14 Self::Dev => "dev",
15 Self::Release => "release",
16 Self::Custom(custom) => custom,
17 })
18 }
19}
20
21impl std::str::FromStr for Profile {
22 type Err = Error;
23
24 fn from_str(profile: &str) -> Result<Self, Self::Err> {
25 Ok(match profile {
26 "dev" => Profile::Dev,
27 "release" => Profile::Release,
28 custom => Profile::Custom(custom.into()),
29 })
30 }
31}
32
33impl AsRef<Path> for Profile {
34 fn as_ref(&self) -> &Path {
35 Path::new(match self {
36 Self::Dev => "debug",
37 Self::Release => "release",
38 Self::Custom(profile) => profile.as_str(),
39 })
40 }
41}