pub struct RequestParameter {
pub name: Cow<'static, str>,
pub value: Option<Value>,
pub input_files: Option<Vec<InputFileRef>>,
}Expand description
A single named parameter sent to the Telegram Bot API.
§Relationship to Python source
| Python attribute | Rust field |
|---|---|
name | RequestParameter::name |
value | RequestParameter::value |
input_files | RequestParameter::input_files |
The json_value and multipart_data Python properties are implemented as
methods here: RequestParameter::json_value and
RequestParameter::multipart_data.
Fields§
§name: Cow<'static, str>The API parameter name, e.g. "chat_id" or "photo".
value: Option<Value>The JSON-serialisable value. None is used when the parameter consists
solely of a file that must be uploaded without an attach URI (the Python
branch return None, [value]).
input_files: Option<Vec<InputFileRef>>Files to upload together with this parameter.
Implementations§
Source§impl RequestParameter
impl RequestParameter
Sourcepub fn new(name: impl Into<Cow<'static, str>>, value: impl Into<Value>) -> Self
pub fn new(name: impl Into<Cow<'static, str>>, value: impl Into<Value>) -> Self
Construct a plain (non-file) parameter.
use rust_tg_bot_raw::request::request_parameter::RequestParameter;
use serde_json::json;
let p = RequestParameter::new("chat_id", json!(12345));
assert_eq!(p.json_value().unwrap(), "12345");Sourcepub fn with_files(
name: impl Into<Cow<'static, str>>,
value: impl Into<Value>,
files: Vec<InputFileRef>,
) -> Self
pub fn with_files( name: impl Into<Cow<'static, str>>, value: impl Into<Value>, files: Vec<InputFileRef>, ) -> Self
Construct a parameter that carries attached files alongside a JSON value.
Sourcepub fn file_only(name: impl Into<Cow<'static, str>>, file: InputFileRef) -> Self
pub fn file_only(name: impl Into<Cow<'static, str>>, file: InputFileRef) -> Self
Construct a file-only parameter where the JSON value is absent (the
Python return None, [value] case).
Sourcepub fn json_value(&self) -> Option<String>
pub fn json_value(&self) -> Option<String>
The JSON-encoded string representation of Self::value, or None
when the value is absent.
Mirrors RequestParameter.json_value in Python:
strvalues are returned as-is (without extra JSON quotes).- All other values are serialised with
serde_json::to_string.
use rust_tg_bot_raw::request::request_parameter::RequestParameter;
use serde_json::json;
let string_param = RequestParameter::new("text", json!("hello"));
// String values are returned verbatim, not double-encoded.
assert_eq!(string_param.json_value().unwrap(), "hello");
let int_param = RequestParameter::new("count", json!(42));
assert_eq!(int_param.json_value().unwrap(), "42");
let bool_param = RequestParameter::new("enabled", json!(true));
assert_eq!(bool_param.json_value().unwrap(), "true");Sourcepub fn multipart_data(&self) -> Option<Vec<(String, &InputFileRef)>>
pub fn multipart_data(&self) -> Option<Vec<(String, &InputFileRef)>>
Produce the multipart parts contributed by this parameter’s files.
Returns None when there are no attached files.
The returned iterator yields (part_name, file) pairs where part_name
is either the file’s attach_name or, when absent, the parameter name.
This mirrors the Python dict comprehension:
{(input_file.attach_name or self.name): input_file.field_tuple ...}Trait Implementations§
Source§impl Clone for RequestParameter
impl Clone for RequestParameter
Source§fn clone(&self) -> RequestParameter
fn clone(&self) -> RequestParameter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more