rpgmvx_types/
move_command_parameter.rs1use ruby_marshal::FromValue;
2use ruby_marshal::FromValueContext;
3use ruby_marshal::FromValueError;
4use ruby_marshal::IntoValue;
5use ruby_marshal::IntoValueError;
6use ruby_marshal::Value;
7use ruby_marshal::ValueArena;
8use ruby_marshal::ValueHandle;
9use ruby_marshal::ValueKind;
10
11#[derive(Debug)]
12pub enum MoveCommandParameterFromValueError {
13 UnexpectedValueKind { kind: ValueKind },
14}
15
16impl std::fmt::Display for MoveCommandParameterFromValueError {
17 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18 match self {
19 Self::UnexpectedValueKind { kind } => {
20 write!(
21 f,
22 "unexpected value kind for move command parameter: {kind:?}"
23 )
24 }
25 }
26 }
27}
28
29impl std::error::Error for MoveCommandParameterFromValueError {}
30
31#[derive(Debug, serde::Serialize, serde::Deserialize)]
32pub enum MoveCommandParameter {
33 Int(i32),
34}
35
36impl<'a> FromValue<'a> for MoveCommandParameter {
37 fn from_value(_ctx: &FromValueContext<'a>, value: &Value) -> Result<Self, FromValueError> {
38 match value {
39 Value::Fixnum(value) => {
40 let value = value.value();
41 Ok(Self::Int(value))
42 }
43 _ => Err(FromValueError::new_other(
44 MoveCommandParameterFromValueError::UnexpectedValueKind { kind: value.kind() },
45 )),
46 }
47 }
48}
49
50impl IntoValue for MoveCommandParameter {
51 fn into_value(self, arena: &mut ValueArena) -> Result<ValueHandle, IntoValueError> {
52 match self {
53 Self::Int(value) => value.into_value(arena),
54 }
55 }
56}