Deserialize a value of this type from core Wasm stack values.
(
cx: &mut LiftContext<'_>,
ty: InterfaceType,
src: &mut Iter<'_, ValRaw>,
)
| 98 | impl Val { |
| 99 | /// Deserialize a value of this type from core Wasm stack values. |
| 100 | pub(crate) fn lift( |
| 101 | cx: &mut LiftContext<'_>, |
| 102 | ty: InterfaceType, |
| 103 | src: &mut Iter<'_, ValRaw>, |
| 104 | ) -> Result<Val> { |
| 105 | Ok(match ty { |
| 106 | InterfaceType::Bool => Val::Bool(bool::linear_lift_from_flat(cx, ty, next(src))?), |
| 107 | InterfaceType::S8 => Val::S8(i8::linear_lift_from_flat(cx, ty, next(src))?), |
| 108 | InterfaceType::U8 => Val::U8(u8::linear_lift_from_flat(cx, ty, next(src))?), |
| 109 | InterfaceType::S16 => Val::S16(i16::linear_lift_from_flat(cx, ty, next(src))?), |
| 110 | InterfaceType::U16 => Val::U16(u16::linear_lift_from_flat(cx, ty, next(src))?), |
| 111 | InterfaceType::S32 => Val::S32(i32::linear_lift_from_flat(cx, ty, next(src))?), |
| 112 | InterfaceType::U32 => Val::U32(u32::linear_lift_from_flat(cx, ty, next(src))?), |
| 113 | InterfaceType::S64 => Val::S64(i64::linear_lift_from_flat(cx, ty, next(src))?), |
| 114 | InterfaceType::U64 => Val::U64(u64::linear_lift_from_flat(cx, ty, next(src))?), |
| 115 | InterfaceType::Float32 => Val::Float32(f32::linear_lift_from_flat(cx, ty, next(src))?), |
| 116 | InterfaceType::Float64 => Val::Float64(f64::linear_lift_from_flat(cx, ty, next(src))?), |
| 117 | InterfaceType::Char => Val::Char(char::linear_lift_from_flat(cx, ty, next(src))?), |
| 118 | InterfaceType::Own(_) | InterfaceType::Borrow(_) => { |
| 119 | Val::Resource(ResourceAny::linear_lift_from_flat(cx, ty, next(src))?) |
| 120 | } |
| 121 | InterfaceType::String => Val::String(<_>::linear_lift_from_flat( |
| 122 | cx, |
| 123 | ty, |
| 124 | &[*next(src), *next(src)], |
| 125 | )?), |
| 126 | InterfaceType::List(i) => { |
| 127 | let (ptr, len) = lift_flat_pointer_pair(cx, src)?; |
| 128 | load_list(cx, i, ptr, len)? |
| 129 | } |
| 130 | InterfaceType::Map(i) => { |
| 131 | let (ptr, len) = lift_flat_pointer_pair(cx, src)?; |
| 132 | load_map(cx, i, ptr, len)? |
| 133 | } |
| 134 | InterfaceType::Record(i) => Val::Record( |
| 135 | cx.types[i] |
| 136 | .fields |
| 137 | .iter() |
| 138 | .map(|field| { |
| 139 | let val = Self::lift(cx, field.ty, src)?; |
| 140 | Ok((field.name.to_string(), val)) |
| 141 | }) |
| 142 | .collect::<Result<_>>()?, |
| 143 | ), |
| 144 | InterfaceType::Tuple(i) => Val::Tuple( |
| 145 | cx.types[i] |
| 146 | .types |
| 147 | .iter() |
| 148 | .map(|ty| Self::lift(cx, *ty, src)) |
| 149 | .collect::<Result<_>>()?, |
| 150 | ), |
| 151 | InterfaceType::Variant(i) => { |
| 152 | let vty = &cx.types[i]; |
| 153 | let (discriminant, value) = lift_variant( |
| 154 | cx, |
| 155 | cx.types.canonical_abi(&ty).flat_count(usize::MAX).unwrap(), |
| 156 | vty.cases.values().copied(), |
| 157 | src, |
no test coverage detected