mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Make more functions const
This commit is contained in:
parent
2ae03963c7
commit
7cd36d9c40
8 changed files with 17 additions and 8 deletions
|
@ -10,6 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- `rocksdb-storage` feature and associated items (See [PR #761](https://github.com/teloxide/teloxide/pull/761) for reasoning) [**BC**]
|
||||
|
||||
## Changed
|
||||
|
||||
- The following functions were made `const`:
|
||||
- `Dialogue::{new, chat_id}`
|
||||
- `Polling::builder`
|
||||
- `StatefulListener::new_with_hints`
|
||||
- `CommandDescriptions::new`
|
||||
- `respond`
|
||||
|
||||
## 0.11.1 - 2022-10-31
|
||||
|
||||
### Added
|
||||
|
|
|
@ -130,7 +130,7 @@ impl Bot {
|
|||
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||
/// [issue 223]: https://github.com/teloxide/teloxide/issues/223
|
||||
pub fn from_env_with_client(client: Client) -> Self {
|
||||
Self::with_client(&get_env(TELOXIDE_TOKEN), client)
|
||||
Self::with_client(get_env(TELOXIDE_TOKEN), client)
|
||||
}
|
||||
|
||||
/// Sets a custom API URL.
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn client_from_env() -> reqwest::Client {
|
|||
let builder = default_reqwest_settings();
|
||||
|
||||
match std::env::var(TELOXIDE_PROXY).ok() {
|
||||
Some(proxy) => builder.proxy(Proxy::all(&proxy).expect("reqwest::Proxy creation failed")),
|
||||
Some(proxy) => builder.proxy(Proxy::all(proxy).expect("reqwest::Proxy creation failed")),
|
||||
None => builder,
|
||||
}
|
||||
.build()
|
||||
|
|
|
@ -141,13 +141,13 @@ where
|
|||
/// Constructs a new dialogue with `storage` (where dialogues are stored)
|
||||
/// and `chat_id` of a current dialogue.
|
||||
#[must_use]
|
||||
pub fn new(storage: Arc<S>, chat_id: ChatId) -> Self {
|
||||
pub const fn new(storage: Arc<S>, chat_id: ChatId) -> Self {
|
||||
Self { storage, chat_id, _phantom: PhantomData }
|
||||
}
|
||||
|
||||
/// Returns a chat ID associated with this dialogue.
|
||||
#[must_use]
|
||||
pub fn chat_id(&self) -> ChatId {
|
||||
pub const fn chat_id(&self) -> ChatId {
|
||||
self.chat_id
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ pub trait AsUpdateStream<'a> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn assert_update_listener<L>(listener: L) -> L
|
||||
pub(crate) const fn assert_update_listener<L>(listener: L) -> L
|
||||
where
|
||||
L: UpdateListener,
|
||||
{
|
||||
|
|
|
@ -250,7 +250,7 @@ where
|
|||
<R as Requester>::GetUpdates: Send,
|
||||
{
|
||||
/// Returns a builder for polling update listener.
|
||||
pub fn builder(bot: R) -> PollingBuilder<R> {
|
||||
pub const fn builder(bot: R) -> PollingBuilder<R> {
|
||||
PollingBuilder {
|
||||
bot,
|
||||
timeout: None,
|
||||
|
|
|
@ -55,7 +55,7 @@ impl<St, Assf, Sf> StatefulListener<St, Assf, Sf, Haufn<St>, Thfn<St>> {
|
|||
|
||||
impl<St, Assf, Sf, Hauf, Thf> StatefulListener<St, Assf, Sf, Hauf, Thf> {
|
||||
/// Creates a new stateful listener from its components.
|
||||
pub fn new_with_hints(
|
||||
pub const fn new_with_hints(
|
||||
state: St,
|
||||
stream: Assf,
|
||||
stop_token: Sf,
|
||||
|
|
|
@ -298,7 +298,7 @@ pub struct CommandDescription<'a> {
|
|||
impl<'a> CommandDescriptions<'a> {
|
||||
/// Creates new [`CommandDescriptions`] from a list of command descriptions.
|
||||
#[must_use]
|
||||
pub fn new(descriptions: &'a [CommandDescription<'a>]) -> Self {
|
||||
pub const fn new(descriptions: &'a [CommandDescription<'a>]) -> Self {
|
||||
Self { global_description: None, descriptions, bot_username: None }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue