fn read_type()

in uniffi_meta/src/reader.rs [137:207]


    fn read_type(&mut self) -> Result<Type> {
        let value = self.read_u8()?;
        Ok(match value {
            codes::TYPE_U8 => Type::UInt8,
            codes::TYPE_I8 => Type::Int8,
            codes::TYPE_U16 => Type::UInt16,
            codes::TYPE_I16 => Type::Int16,
            codes::TYPE_U32 => Type::UInt32,
            codes::TYPE_I32 => Type::Int32,
            codes::TYPE_U64 => Type::UInt64,
            codes::TYPE_I64 => Type::Int64,
            codes::TYPE_F32 => Type::Float32,
            codes::TYPE_F64 => Type::Float64,
            codes::TYPE_BOOL => Type::Boolean,
            codes::TYPE_STRING => Type::String,
            codes::TYPE_DURATION => Type::Duration,
            codes::TYPE_SYSTEM_TIME => Type::Timestamp,
            codes::TYPE_RECORD => Type::Record {
                module_path: self.read_string()?,
                name: self.read_string()?,
            },
            codes::TYPE_ENUM => Type::Enum {
                module_path: self.read_string()?,
                name: self.read_string()?,
            },
            codes::TYPE_INTERFACE => Type::Object {
                module_path: self.read_string()?,
                name: self.read_string()?,
                imp: ObjectImpl::Struct,
            },
            codes::TYPE_TRAIT_INTERFACE => Type::Object {
                module_path: self.read_string()?,
                name: self.read_string()?,
                imp: ObjectImpl::Trait,
            },
            codes::TYPE_CALLBACK_TRAIT_INTERFACE => Type::Object {
                module_path: self.read_string()?,
                name: self.read_string()?,
                imp: ObjectImpl::CallbackTrait,
            },
            codes::TYPE_CALLBACK_INTERFACE => Type::CallbackInterface {
                module_path: self.read_string()?,
                name: self.read_string()?,
            },
            codes::TYPE_CUSTOM => Type::Custom {
                module_path: self.read_string()?,
                name: self.read_string()?,
                builtin: Box::new(self.read_type()?),
            },
            codes::TYPE_OPTION => Type::Optional {
                inner_type: Box::new(self.read_type()?),
            },
            codes::TYPE_VEC => {
                let inner_type = self.read_type()?;
                if inner_type == Type::UInt8 {
                    Type::Bytes
                } else {
                    Type::Sequence {
                        inner_type: Box::new(inner_type),
                    }
                }
            }
            codes::TYPE_HASH_MAP => Type::Map {
                key_type: Box::new(self.read_type()?),
                value_type: Box::new(self.read_type()?),
            },
            codes::TYPE_UNIT => bail!("Unexpected TYPE_UNIT"),
            codes::TYPE_RESULT => bail!("Unexpected TYPE_RESULT"),
            _ => bail!("Unexpected metadata type code: {value:?}"),
        })
    }