1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Inspired by https://github.com/tokio-rs/axum/tree/main/axum/src/routing

//! A library for creating your own VK bot
//!
//! # Compatibility
//!
//! safevk is using [tokio] under the hood, and works with
//! [5.199](https://dev.vk.com/en/reference/version/5.199) API version.

//#![deny(unreachable_pub)]
//#![allow(elided_lifetimes_in_paths, clippy::type_complexity)]
//#![forbid(unsafe_code)]
//#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]

mod reqwest_ext;

pub mod extract;
pub mod handler;
pub mod listeners;
pub mod responses;
#[cfg(feature = "tokio")]
pub mod start_polling;
pub mod util;

pub use self::listeners::SafeVk;
pub use self::reqwest_ext::{RequestBuilder, VERSION, VK};
pub use util::{Error, Result};

#[cfg(feature = "tokio")]
pub use self::start_polling::start_polling;

#[macro_export]
macro_rules! parse_response {
    ($value:expr, $type:ty) => {{
        use serde::de::Error;
        let parsed_result = match $value.get("response") {
            Some(response_value) => serde_json::from_value::<$type>(response_value.clone()),
            None => serde_json::from_value::<$type>($value.clone()),
        };
        parsed_result.map_err(|e| serde_json::Error::custom(e.to_string()))
    }};
}