summaryrefslogtreecommitdiff
path: root/cli/msg.rs
blob: 3e5000296ca995e07de366c0c2f3f836bf2d1fab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

// Warning! The values in this enum are duplicated in js/compiler.ts
// Update carefully!
use serde::Serialize;
use serde::Serializer;

#[allow(non_camel_case_types)]
#[repr(i32)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum MediaType {
  JavaScript = 0,
  JSX = 1,
  TypeScript = 2,
  TSX = 3,
  Json = 4,
  Wasm = 5,
  Unknown = 6,
}

impl Serialize for MediaType {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
  where
    S: Serializer,
  {
    let value: i32 = match self {
      MediaType::JavaScript => 0 as i32,
      MediaType::JSX => 1 as i32,
      MediaType::TypeScript => 2 as i32,
      MediaType::TSX => 3 as i32,
      MediaType::Json => 4 as i32,
      MediaType::Wasm => 5 as i32,
      MediaType::Unknown => 6 as i32,
    };
    Serialize::serialize(&value, serializer)
  }
}

pub fn enum_name_media_type(mt: MediaType) -> &'static str {
  match mt {
    MediaType::JavaScript => "JavaScript",
    MediaType::JSX => "JSX",
    MediaType::TypeScript => "TypeScript",
    MediaType::TSX => "TSX",
    MediaType::Json => "Json",
    MediaType::Wasm => "Wasm",
    MediaType::Unknown => "Unknown",
  }
}

// Warning! The values in this enum are duplicated in js/compiler.ts
// Update carefully!
#[allow(non_camel_case_types)]
#[repr(i32)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum CompilerRequestType {
  Compile = 0,
  Bundle = 1,
  RuntimeCompile = 2,
  RuntimeBundle = 3,
  RuntimeTranspile = 4,
}

impl Serialize for CompilerRequestType {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
  where
    S: Serializer,
  {
    let value: i32 = match self {
      CompilerRequestType::Compile => 0 as i32,
      CompilerRequestType::Bundle => 1 as i32,
      CompilerRequestType::RuntimeCompile => 2 as i32,
      CompilerRequestType::RuntimeBundle => 3 as i32,
      CompilerRequestType::RuntimeTranspile => 4 as i32,
    };
    Serialize::serialize(&value, serializer)
  }
}