codama_nodes/shared/
instruction_input_value_node.rs1use crate::{HasKind, InstructionInputValueNode, ValueNode};
2use codama_errors::CodamaError;
3
4impl From<ValueNode> for InstructionInputValueNode {
10 fn from(value: ValueNode) -> Self {
11 match value {
12 ValueNode::Array(value) => Self::ArrayValue(value),
13 ValueNode::Boolean(value) => Self::BooleanValue(value),
14 ValueNode::Bytes(value) => Self::BytesValue(value),
15 ValueNode::Constant(value) => Self::ConstantValue(value),
16 ValueNode::Enum(value) => Self::EnumValue(value),
17 ValueNode::Map(value) => Self::MapValue(value),
18 ValueNode::None(value) => Self::NoneValue(value),
19 ValueNode::Number(value) => Self::NumberValue(value),
20 ValueNode::PublicKey(value) => Self::PublicKeyValue(value),
21 ValueNode::Set(value) => Self::SetValue(value),
22 ValueNode::Some(value) => Self::SomeValue(value),
23 ValueNode::String(value) => Self::StringValue(value),
24 ValueNode::Struct(value) => Self::StructValue(value),
25 ValueNode::Tuple(value) => Self::TupleValue(value),
26 }
27 }
28}
29
30impl TryFrom<InstructionInputValueNode> for ValueNode {
34 type Error = CodamaError;
35
36 fn try_from(value: InstructionInputValueNode) -> Result<Self, Self::Error> {
37 match value {
38 InstructionInputValueNode::ArrayValue(value) => Ok(Self::Array(value)),
39 InstructionInputValueNode::BooleanValue(value) => Ok(Self::Boolean(value)),
40 InstructionInputValueNode::BytesValue(value) => Ok(Self::Bytes(value)),
41 InstructionInputValueNode::ConstantValue(value) => Ok(Self::Constant(value)),
42 InstructionInputValueNode::EnumValue(value) => Ok(Self::Enum(value)),
43 InstructionInputValueNode::MapValue(value) => Ok(Self::Map(value)),
44 InstructionInputValueNode::NoneValue(value) => Ok(Self::None(value)),
45 InstructionInputValueNode::NumberValue(value) => Ok(Self::Number(value)),
46 InstructionInputValueNode::PublicKeyValue(value) => Ok(Self::PublicKey(value)),
47 InstructionInputValueNode::SetValue(value) => Ok(Self::Set(value)),
48 InstructionInputValueNode::SomeValue(value) => Ok(Self::Some(value)),
49 InstructionInputValueNode::StringValue(value) => Ok(Self::String(value)),
50 InstructionInputValueNode::StructValue(value) => Ok(Self::Struct(value)),
51 InstructionInputValueNode::TupleValue(value) => Ok(Self::Tuple(value)),
52 _ => Err(CodamaError::InvalidNodeConversion {
53 from: value.kind().to_string(),
54 into: "ValueNode".to_string(),
55 }),
56 }
57 }
58}