Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Dec 13, 2024
1 parent 360677c commit 6e28fee
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions wasm-rpc/src/type_annotated_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,43 +140,41 @@ fn create_from_type(val: &Value, typ: &Type) -> Result<TypeAnnotatedValue, Vec<S
_ => Err(vec!["Unexpected type; expected an Option type.".to_string()]),
},

Value::Tuple(values) => {
match &typ.r#type {
Some(golem_wasm_ast::analysis::protobuf::r#type::Type::Tuple(typ_tuple)) => {
if values.len() != typ_tuple.elems.len() {
return Err(vec![format!(
"Tuple has unexpected number of elements: {} vs {}",
values.len(),
typ_tuple.elems.len(),
)]);
}
Value::Tuple(values) => match &typ.r#type {
Some(golem_wasm_ast::analysis::protobuf::r#type::Type::Tuple(typ_tuple)) => {
if values.len() != typ_tuple.elems.len() {
return Err(vec![format!(
"Tuple has unexpected number of elements: {} vs {}",
values.len(),
typ_tuple.elems.len(),
)]);
}

let mut errors = vec![];
let mut results = vec![];
let mut errors = vec![];
let mut results = vec![];

for (value, tpe) in values.iter().zip(&typ_tuple.elems) {
match create_from_type(value, tpe) {
Ok(result) => results.push(result),
Err(errs) => errors.extend(errs),
}
for (value, tpe) in values.iter().zip(&typ_tuple.elems) {
match create_from_type(value, tpe) {
Ok(result) => results.push(result),
Err(errs) => errors.extend(errs),
}
}

if errors.is_empty() {
Ok(TypeAnnotatedValue::Tuple(TypedTuple {
typ: typ_tuple.elems.clone(),
value: results
.into_iter()
.map(|v| RootTypeAnnotatedValue {
type_annotated_value: Some(v),
})
.collect(),
}))
} else {
Err(errors)
}
if errors.is_empty() {
Ok(TypeAnnotatedValue::Tuple(TypedTuple {
typ: typ_tuple.elems.clone(),
value: results
.into_iter()
.map(|v| RootTypeAnnotatedValue {
type_annotated_value: Some(v),
})
.collect(),
}))
} else {
Err(errors)
}
_ => Err(vec!["Unexpected type; expected a Tuple type.".to_string()]),
}
_ => Err(vec!["Unexpected type; expected a Tuple type.".to_string()]),
},

Value::List(values) => match &typ.r#type {
Expand Down

0 comments on commit 6e28fee

Please sign in to comment.