"override" mention and tme_url on Me

That's not **really** an override, but by adding an inherent methods
we "hide" methods from `Deref<Target = User>`, that allows us to return
non-option types from `me.mention()` and `me.tme_url()` -- bots must
always have usernames.
This commit is contained in:
Maybe Waffle 2022-04-02 22:56:32 +04:00
parent df9ffe8918
commit b3c0d00b7d
2 changed files with 11 additions and 0 deletions

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `UserId::{url, is_anonymous, is_channel, is_telegram}` convenience functions ([#197][pr197])
- `User::{tme_url, preferably_tme_url}` convenience functions ([#197][pr197])
- `Me::username` and `Deref<Target = User>` implementation for `Me` ([#197][pr197])
- `Me::{mention, tme_url}` ([#197][pr197])
[pr197]: https://github.com/teloxide/teloxide-core/pull/197

View file

@ -32,6 +32,16 @@ impl Me {
.as_deref()
.expect("Bots must have usernames")
}
/// Returns a username mention of this bot.
pub fn mention(&self) -> String {
format!("@{}", self.username())
}
/// Returns an URL that links to this bot in the form of `t.me/<...>`.
pub fn tme_url(&self) -> reqwest::Url {
format!("https://t.me/{}", self.username()).parse().unwrap()
}
}
impl Deref for Me {