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

@@ -8,7 +8,7 @@ pub struct ScootalooError {
impl ScootalooError { impl ScootalooError {
pub fn new(msg: &str) -> ScootalooError { pub fn new(msg: &str) -> ScootalooError {
ScootalooError { ScootalooError {
details: String::from(msg), details: msg.to_string(),
} }
} }
} }

View File

@@ -96,7 +96,7 @@ pub async fn run(config: Config) {
}, },
}; };
let mastodon_media_ids = match mastodon.media(Cow::from(String::from(&local_tweet_media_path))) { let mastodon_media_ids = match mastodon.media(Cow::from(local_tweet_media_path.to_owned())) {
Ok(m) => { Ok(m) => {
remove_file(&local_tweet_media_path) remove_file(&local_tweet_media_path)
.await .await

View File

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

View File

@@ -16,7 +16,7 @@ pub fn read_state(conn: &Connection, s: Option<u64>) -> Result<Option<TweetToToo
let query: String; let query: String;
match s { match s {
Some(i) => query = format!("SELECT * FROM tweet_to_toot WHERE tweet_id = {}", i), Some(i) => query = format!("SELECT * FROM tweet_to_toot WHERE tweet_id = {}", i),
None => query = String::from("SELECT * FROM tweet_to_toot ORDER BY tweet_id DESC LIMIT 1"), None => query = "SELECT * FROM tweet_to_toot ORDER BY tweet_id DESC LIMIT 1".to_string(),
}; };
let mut stmt = conn.prepare(&query)?; let mut stmt = conn.prepare(&query)?;
@@ -116,7 +116,7 @@ mod tests {
let t_in = TweetToToot { let t_in = TweetToToot {
tweet_id: 123456789, tweet_id: 123456789,
toot_id: String::from("987654321"), toot_id: "987654321".to_string(),
}; };
write_state(&conn, t_in).unwrap(); write_state(&conn, t_in).unwrap();
@@ -131,7 +131,7 @@ mod tests {
}).unwrap(); }).unwrap();
assert_eq!(t_out.tweet_id, 123456789); assert_eq!(t_out.tweet_id, 123456789);
assert_eq!(t_out.toot_id, String::from("987654321")); assert_eq!(t_out.toot_id, "987654321".to_string());
remove_file(d).unwrap(); remove_file(d).unwrap();
} }

View File

@@ -16,8 +16,8 @@ use egg_mode::{
/// Gets Twitter oauth2 token /// Gets Twitter oauth2 token
pub fn get_oauth2_token(config: &TwitterConfig) -> Token { pub fn get_oauth2_token(config: &TwitterConfig) -> Token {
let con_token = KeyPair::new(String::from(&config.consumer_key), String::from(&config.consumer_secret)); let con_token = KeyPair::new(config.consumer_key.to_owned(),config.consumer_secret.to_owned());
let access_token = KeyPair::new(String::from(&config.access_key), String::from(&config.access_secret)); let access_token = KeyPair::new(config.access_key.to_owned(), config.access_secret.to_owned());
Token::Access { Token::Access {
consumer: con_token, consumer: con_token,
@@ -28,7 +28,7 @@ pub fn get_oauth2_token(config: &TwitterConfig) -> Token {
/// Gets Twitter user timeline /// Gets Twitter user timeline
pub async fn get_user_timeline(config: &TwitterConfig, token: Token, lid: Option<u64>) -> Result<Vec<Tweet>, Box<dyn Error>> { pub async fn get_user_timeline(config: &TwitterConfig, token: Token, lid: Option<u64>) -> Result<Vec<Tweet>, Box<dyn Error>> {
// fix the page size to 200 as it is the maximum Twitter authorizes // fix the page size to 200 as it is the maximum Twitter authorizes
let (_, feed) = user_timeline(UserID::from(String::from(&config.username)), true, false, &token) let (_, feed) = user_timeline(UserID::from(config.username.to_owned()), true, false, &token)
.with_page_size(200) .with_page_size(200)
.older(lid) .older(lid)
.await?; .await?;