teloxide-core 0.13.0

Core part of the `teloxide` library - telegram bot API client
Documentation
use crate::codegen::schema::Type;

pub enum Convert {
    #[allow(dead_code)]
    Id(Type),
    Into(Type),
    Collect(Type),
}

pub fn convert_for(ty: &Type) -> Convert {
    match ty {
        ty @ Type::True
        | ty @ Type::u8
        | ty @ Type::u16
        | ty @ Type::u32
        | ty @ Type::i32
        | ty @ Type::u64
        | ty @ Type::i64
        | ty @ Type::f64
        | ty @ Type::bool => Convert::Id(ty.clone()),
        ty @ Type::String => Convert::Into(ty.clone()),
        Type::Option(inner) => convert_for(inner),
        Type::ArrayOf(ty) => Convert::Collect((**ty).clone()),
        Type::RawTy(s) => match s.as_str() {
            raw @ "Recipient" | raw @ "ChatId" | raw @ "TargetMessage" | raw @ "ReplyMarkup" => {
                Convert::Into(Type::RawTy(raw.to_owned()))
            }
            raw => Convert::Id(Type::RawTy(raw.to_owned())),
        },
        ty @ Type::Url => Convert::Id(ty.clone()),
        ty @ Type::DateTime => Convert::Into(ty.clone()),
    }
}