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
//! Defines the placeholder for the type of model engine in the header.
/// Defines the type of engine being used to run the model.
///
/// # Fields
/// * `Native` - The native engine which will be native rust and linfa.
/// * `PyTorch` - The PyTorch engine which will be PyTorch and tch-rs.
/// * `Undefined` - The undefined engine which will be used when the engine is not defined.
#[derive(Debug, PartialEq)]
pub enum Engine {
Native,
PyTorch,
Undefined
}
impl Engine {
/// Creates a new `Engine` struct with the undefined engine.
///
/// # Returns
/// A new `Engine` struct with the undefined engine.
pub fn fresh() -> Self {
Engine::Undefined
}
/// Creates a new `Engine` struct from a string.
///
/// # Arguments
/// * `engine` - The engine as a string.
///
/// # Returns
/// A new `Engine` struct.
pub fn from_string(engine: String) -> Self {
match engine.as_str() {
"native" => Engine::Native,
"pytorch" => Engine::PyTorch,
_ => Engine::Undefined,
}
}
/// Translates the struct to a string.
///
/// # Returns
/// * `String` - The struct as a string.
pub fn to_string(&self) -> String {
match self {
Engine::Native => "native".to_string(),
Engine::PyTorch => "pytorch".to_string(),
Engine::Undefined => "".to_string(),
}
}
}