Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Jan 30, 2024
1 parent 6a45c66 commit 3097230
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions rust/candid/src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,22 @@ impl IDLValue {
(_, TypeInner::Opt(_)) if !from_parser => IDLValue::None,
(IDLValue::Blob(blob), ty) if ty.is_blob(env) => IDLValue::Blob(blob.to_vec()),
(IDLValue::Vec(vec), ty) if ty.is_blob(env) => {
let blob = vec
.iter()
.filter_map(|x| match x {
IDLValue::Nat8(n) => Some(*n),
IDLValue::Number(n) => n.parse::<u8>().ok(),
_ => None,
})
.collect();
let mut blob = Vec::with_capacity(vec.len());
for e in vec.iter() {
match e {
IDLValue::Nat8(n) => blob.push(*n),
IDLValue::Number(n) => blob.push(n.parse::<u8>()?),
_ => {
return Err(Error::msg(format!(
"type mismatch: {e} cannot be of type nat8"
)))
}
}
}
IDLValue::Blob(blob)
}
(IDLValue::Vec(vec), TypeInner::Vec(ty)) => {
let mut res = Vec::new();
let mut res = Vec::with_capacity(vec.len());
for e in vec.iter() {
let v = e.annotate_type(from_parser, env, ty)?;
res.push(v);
Expand Down

0 comments on commit 3097230

Please sign in to comment.