mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
refactor(fmt): delete String::from() format in favor of .to_string()/to_owned()
This commit is contained in:
@@ -8,7 +8,7 @@ pub struct ScootalooError {
|
||||
impl ScootalooError {
|
||||
pub fn new(msg: &str) -> ScootalooError {
|
||||
ScootalooError {
|
||||
details: String::from(msg),
|
||||
details: msg.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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) => {
|
||||
remove_file(&local_tweet_media_path)
|
||||
.await
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -16,7 +16,7 @@ pub fn read_state(conn: &Connection, s: Option<u64>) -> Result<Option<TweetToToo
|
||||
let query: String;
|
||||
match s {
|
||||
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)?;
|
||||
@@ -116,7 +116,7 @@ mod tests {
|
||||
|
||||
let t_in = TweetToToot {
|
||||
tweet_id: 123456789,
|
||||
toot_id: String::from("987654321"),
|
||||
toot_id: "987654321".to_string(),
|
||||
};
|
||||
|
||||
write_state(&conn, t_in).unwrap();
|
||||
@@ -131,7 +131,7 @@ mod tests {
|
||||
}).unwrap();
|
||||
|
||||
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();
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ use egg_mode::{
|
||||
|
||||
/// Gets Twitter oauth2 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 access_token = KeyPair::new(String::from(&config.access_key), String::from(&config.access_secret));
|
||||
let con_token = KeyPair::new(config.consumer_key.to_owned(),config.consumer_secret.to_owned());
|
||||
let access_token = KeyPair::new(config.access_key.to_owned(), config.access_secret.to_owned());
|
||||
|
||||
Token::Access {
|
||||
consumer: con_token,
|
||||
@@ -28,7 +28,7 @@ pub fn get_oauth2_token(config: &TwitterConfig) -> Token {
|
||||
/// Gets Twitter user timeline
|
||||
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
|
||||
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)
|
||||
.older(lid)
|
||||
.await?;
|
||||
|
Reference in New Issue
Block a user