surrealml_core/storage/header/engine.rs
1//! Defines the placeholder for the type of model engine in the header.
2
3
4/// Defines the type of engine being used to run the model.
5///
6/// # Fields
7/// * `Native` - The native engine which will be native rust and linfa.
8/// * `PyTorch` - The PyTorch engine which will be PyTorch and tch-rs.
9/// * `Undefined` - The undefined engine which will be used when the engine is not defined.
10#[derive(Debug, PartialEq)]
11pub enum Engine {
12 Native,
13 PyTorch,
14 Undefined
15}
16
17
18impl Engine {
19
20 /// Creates a new `Engine` struct with the undefined engine.
21 ///
22 /// # Returns
23 /// A new `Engine` struct with the undefined engine.
24 pub fn fresh() -> Self {
25 Engine::Undefined
26 }
27
28 /// Creates a new `Engine` struct from a string.
29 ///
30 /// # Arguments
31 /// * `engine` - The engine as a string.
32 ///
33 /// # Returns
34 /// A new `Engine` struct.
35 pub fn from_string(engine: String) -> Self {
36 match engine.as_str() {
37 "native" => Engine::Native,
38 "pytorch" => Engine::PyTorch,
39 _ => Engine::Undefined,
40 }
41 }
42
43 /// Translates the struct to a string.
44 ///
45 /// # Returns
46 /// * `String` - The struct as a string.
47 pub fn to_string(&self) -> String {
48 match self {
49 Engine::Native => "native".to_string(),
50 Engine::PyTorch => "pytorch".to_string(),
51 Engine::Undefined => "".to_string(),
52 }
53 }
54
55}