replace return type in url() function to Url from String

This commit is contained in:
p0lunin 2020-01-24 20:12:23 +02:00
parent 7488f96d02
commit d490ed9bc0
5 changed files with 9 additions and 9 deletions

View file

@ -796,7 +796,7 @@ mod getters {
}
impl Message {
pub fn url(&self) -> Option<String> {
pub fn url(&self) -> Option<reqwest::Url> {
match &self.chat.kind {
ChatKind::NonPrivate {
kind:
@ -812,7 +812,7 @@ impl Message {
..
},
..
} => Some(format!("https://t.me/{0}/{1}/", username, self.id)),
} => Some(reqwest::Url::parse(format!("https://t.me/{0}/{1}/", username, self.id).as_str()).unwrap()),
_ => None,
}
}

View file

@ -40,8 +40,8 @@ impl User {
Some(format!("@{}", self.username.as_ref()?))
}
pub fn url(&self) -> String {
format!("tg://user?id={}", self.id)
pub fn url(&self) -> reqwest::Url {
reqwest::Url::parse(format!("tg://user/?id={}", self.id).as_str()).unwrap()
}
}

View file

@ -89,7 +89,7 @@ pub fn escape(s: &str) -> String {
pub fn user_mention_or_link(user: &User) -> String {
match user.mention() {
Some(mention) => mention,
None => link(&user.url(), &user.full_name()),
None => link(user.url().as_str(), &user.full_name()),
}
}
@ -209,7 +209,7 @@ mod tests {
};
assert_eq!(
user_mention_or_link(&user_without_username),
r#"<a href="tg://user?id=123456789">Name</a>"#
r#"<a href="tg://user/?id=123456789">Name</a>"#
)
}
}

View file

@ -123,7 +123,7 @@ pub fn escape_code(s: &str) -> String {
pub fn user_mention_or_link(user: &User) -> String {
match user.mention() {
Some(mention) => mention,
None => link(&user.url(), &user.full_name()),
None => link(user.url().as_str(), &user.full_name()),
}
}
@ -271,7 +271,7 @@ mod tests {
};
assert_eq!(
user_mention_or_link(&user_without_username),
r#"[Name](tg://user?id=123456789)"#
r#"[Name](tg://user/?id=123456789)"#
)
}
}

View file

@ -54,7 +54,7 @@ where
/// use teloxide::utils::parse_command;
/// let text = "/ban 5 hours";
/// let (command, args) = parse_command(text).unwrap();
/// assert_eq!(command, "ban");
/// assert_eq!(command, "/ban");
/// assert_eq!(args, vec!["5", "hours"]);
/// ```
pub fn parse_command(text: &str) -> Option<(&str, Vec<&str>)> {