refactor(fmt): delete String::from() format in favor of .to_string()/to_owned()

This commit is contained in:
VC
2022-04-24 14:20:45 +02:00
parent 734f03f5a9
commit 905793af72
5 changed files with 27 additions and 27 deletions

View File

@@ -29,18 +29,18 @@ fn decode_urls(urls: &Vec<UrlEntity>) -> HashMap<String, String> {
urls.iter()
.filter(|s| s.expanded_url.is_some())
.map(|s|
(String::from(&s.url), String::from(s.expanded_url.as_deref().unwrap()))
(s.url.to_owned(), s.expanded_url.as_deref().unwrap().to_owned())
).collect()
}
/// Gets Mastodon Data
pub fn get_mastodon_token(masto: &MastodonConfig) -> Mastodon {
let data = Data {
base: Cow::from(String::from(&masto.base)),
client_id: Cow::from(String::from(&masto.client_id)),
client_secret: Cow::from(String::from(&masto.client_secret)),
redirect: Cow::from(String::from(&masto.redirect)),
token: Cow::from(String::from(&masto.token)),
base: Cow::from(masto.base.to_owned()),
client_id: Cow::from(masto.client_id.to_owned()),
client_secret: Cow::from(masto.client_secret.to_owned()),
redirect: Cow::from(masto.redirect.to_owned()),
token: Cow::from(masto.token.to_owned()),
};
Mastodon::from(data)
@@ -48,7 +48,7 @@ pub fn get_mastodon_token(masto: &MastodonConfig) -> Mastodon {
/// Builds toot text from tweet
pub fn build_basic_status(tweet: &Tweet) -> String {
let mut toot = String::from(&tweet.text);
let mut toot = tweet.text.to_owned();
for decoded_url in decode_urls(&tweet.entities.urls) {
toot = toot.replace(&decoded_url.0, &decoded_url.1);
@@ -66,10 +66,10 @@ pub fn build_basic_status(tweet: &Tweet) -> String {
/// Most of this function is a direct copy/paste of the official `elefren` crate
pub fn register(host: &str) {
let mut builder = App::builder();
builder.client_name(Cow::from(String::from(env!("CARGO_PKG_NAME"))))
.redirect_uris(Cow::from(String::from("urn:ietf:wg:oauth:2.0:oob")))
builder.client_name(Cow::from(env!("CARGO_PKG_NAME").to_string()))
.redirect_uris(Cow::from("urn:ietf:wg:oauth:2.0:oob".to_string()))
.scopes(Scopes::write_all())
.website(Cow::from(String::from("https://framagit.org/veretcle/scootaloo")));
.website(Cow::from("https://framagit.org/veretcle/scootaloo".to_string()));
let app = builder.build().expect("Cannot build the app");
@@ -102,14 +102,14 @@ mod tests {
let mention_entity = MentionEntity {
id: 12345,
range: (1, 3),
name: String::from("Ta Mere l0l"),
screen_name: String::from("tamerelol"),
name: "Ta Mere l0l".to_string(),
screen_name: "tamerelol".to_string(),
};
let twitter_ums = vec![mention_entity];
let mut expected_mentions = HashMap::new();
expected_mentions.insert(String::from("@tamerelol"), String::from("@tamerelol@twitter.com"));
expected_mentions.insert("@tamerelol".to_string(), "@tamerelol@twitter.com".to_string());
let decoded_mentions = twitter_mentions(&twitter_ums);
@@ -119,23 +119,23 @@ mod tests {
#[test]
fn test_decode_urls() {
let url_entity1 = UrlEntity {
display_url: String::from("tamerelol"),
expanded_url: Some(String::from("https://www.nintendojo.fr/dojobar")),
display_url: "tamerelol".to_string(),
expanded_url: Some("https://www.nintendojo.fr/dojobar".to_string()),
range: (1, 3),
url: String::from("https://t.me/tamerelol"),
url: "https://t.me/tamerelol".to_string(),
};
let url_entity2 = UrlEntity {
display_url: String::from("tamerelol"),
display_url: "tamerelol".to_string(),
expanded_url: None,
range: (1, 3),
url: String::from("https://t.me/tamerelol"),
url: "https://t.me/tamerelol".to_string(),
};
let twitter_urls = vec![url_entity1, url_entity2];
let mut expected_urls = HashMap::new();
expected_urls.insert(String::from("https://t.me/tamerelol"), String::from("https://www.nintendojo.fr/dojobar"));
expected_urls.insert("https://t.me/tamerelol".to_string(), "https://www.nintendojo.fr/dojobar".to_string());
let decoded_urls = decode_urls(&twitter_urls);