frakti 0.1.2

Telegram bot API client for Rust, with a focus on single-threaded async runtime support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use super::Error;

/// Shortcut for [`serde_json::to_value`] producing a JSON object with [`crate::Error`].
pub fn encode_object<T>(value: &T) -> Result<serde_json::Map<String, serde_json::Value>, Error>
where
    T: serde::ser::Serialize + std::fmt::Debug,
{
    let json = serde_json::to_value(value).map_err(|error| Error::JsonEncode {
        source: error,
        input: format!("{value:?}"),
    })?;

    let serde_json::Value::Object(object) = json else {
        unreachable!("Telegram API params must serialize to a JSON object");
    };

    Ok(object)
}