use crate::types::*;
use crate::errors::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TdlibParameters {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
use_test_dc: bool,
database_directory: String,
files_directory: String,
use_file_database: bool,
use_chat_info_database: bool,
use_message_database: bool,
use_secret_chats: bool,
api_id: i64,
api_hash: String,
system_language_code: String,
device_model: String,
system_version: String,
application_version: String,
enable_storage_optimizer: bool,
ignore_file_names: bool,
}
impl RObject for TdlibParameters {
#[doc(hidden)] fn td_name(&self) -> &'static str { "tdlibParameters" }
#[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}
impl TdlibParameters {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
pub fn builder() -> RTDTdlibParametersBuilder {
let mut inner = TdlibParameters::default();
inner.td_name = "tdlibParameters".to_string();
inner.extra = Some(Uuid::new_v4().to_string());
RTDTdlibParametersBuilder { inner }
}
pub fn use_test_dc(&self) -> bool { self.use_test_dc }
pub fn database_directory(&self) -> &String { &self.database_directory }
pub fn files_directory(&self) -> &String { &self.files_directory }
pub fn use_file_database(&self) -> bool { self.use_file_database }
pub fn use_chat_info_database(&self) -> bool { self.use_chat_info_database }
pub fn use_message_database(&self) -> bool { self.use_message_database }
pub fn use_secret_chats(&self) -> bool { self.use_secret_chats }
pub fn api_id(&self) -> i64 { self.api_id }
pub fn api_hash(&self) -> &String { &self.api_hash }
pub fn system_language_code(&self) -> &String { &self.system_language_code }
pub fn device_model(&self) -> &String { &self.device_model }
pub fn system_version(&self) -> &String { &self.system_version }
pub fn application_version(&self) -> &String { &self.application_version }
pub fn enable_storage_optimizer(&self) -> bool { self.enable_storage_optimizer }
pub fn ignore_file_names(&self) -> bool { self.ignore_file_names }
}
#[doc(hidden)]
pub struct RTDTdlibParametersBuilder {
inner: TdlibParameters
}
impl RTDTdlibParametersBuilder {
pub fn build(&self) -> TdlibParameters { self.inner.clone() }
pub fn use_test_dc(&mut self, use_test_dc: bool) -> &mut Self {
self.inner.use_test_dc = use_test_dc;
self
}
pub fn database_directory<T: AsRef<str>>(&mut self, database_directory: T) -> &mut Self {
self.inner.database_directory = database_directory.as_ref().to_string();
self
}
pub fn files_directory<T: AsRef<str>>(&mut self, files_directory: T) -> &mut Self {
self.inner.files_directory = files_directory.as_ref().to_string();
self
}
pub fn use_file_database(&mut self, use_file_database: bool) -> &mut Self {
self.inner.use_file_database = use_file_database;
self
}
pub fn use_chat_info_database(&mut self, use_chat_info_database: bool) -> &mut Self {
self.inner.use_chat_info_database = use_chat_info_database;
self
}
pub fn use_message_database(&mut self, use_message_database: bool) -> &mut Self {
self.inner.use_message_database = use_message_database;
self
}
pub fn use_secret_chats(&mut self, use_secret_chats: bool) -> &mut Self {
self.inner.use_secret_chats = use_secret_chats;
self
}
pub fn api_id(&mut self, api_id: i64) -> &mut Self {
self.inner.api_id = api_id;
self
}
pub fn api_hash<T: AsRef<str>>(&mut self, api_hash: T) -> &mut Self {
self.inner.api_hash = api_hash.as_ref().to_string();
self
}
pub fn system_language_code<T: AsRef<str>>(&mut self, system_language_code: T) -> &mut Self {
self.inner.system_language_code = system_language_code.as_ref().to_string();
self
}
pub fn device_model<T: AsRef<str>>(&mut self, device_model: T) -> &mut Self {
self.inner.device_model = device_model.as_ref().to_string();
self
}
pub fn system_version<T: AsRef<str>>(&mut self, system_version: T) -> &mut Self {
self.inner.system_version = system_version.as_ref().to_string();
self
}
pub fn application_version<T: AsRef<str>>(&mut self, application_version: T) -> &mut Self {
self.inner.application_version = application_version.as_ref().to_string();
self
}
pub fn enable_storage_optimizer(&mut self, enable_storage_optimizer: bool) -> &mut Self {
self.inner.enable_storage_optimizer = enable_storage_optimizer;
self
}
pub fn ignore_file_names(&mut self, ignore_file_names: bool) -> &mut Self {
self.inner.ignore_file_names = ignore_file_names;
self
}
}
impl AsRef<TdlibParameters> for TdlibParameters {
fn as_ref(&self) -> &TdlibParameters { self }
}
impl AsRef<TdlibParameters> for RTDTdlibParametersBuilder {
fn as_ref(&self) -> &TdlibParameters { &self.inner }
}