Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce core dependencies #110

Merged
merged 25 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
22e9ec8
Replace rand with getrandom.
Aug 14, 2020
c98a577
replacing rand with getrandom to reduce binary size and compilation t…
ramsayleung Aug 14, 2020
88c97ba
Merge branch 'reduce-core-dependencies' of github.com:samrayleung/rsp…
ramsayleung Aug 14, 2020
08ded2b
Merge branch 'master' into reduce-core-dependencies
ramsayleung Aug 15, 2020
d36adb0
Change alphanum from global variable to a local variable, update desc…
ramsayleung Aug 15, 2020
f6caa06
Change rand dependency into getrandom
marioortizmanero Aug 15, 2020
09ee436
Moved static variable inside function
marioortizmanero Aug 15, 2020
be15092
Optional webbrowser feature
marioortizmanero Aug 15, 2020
2841d99
Optional dotenv feature
marioortizmanero Aug 15, 2020
6d6cbdf
Initial documentation work
marioortizmanero Aug 15, 2020
6b81aca
Merge branch 'reduce-core-dependencies' of github.com:samrayleung/rsp…
ramsayleung Aug 16, 2020
c8cc068
Merge branch 'master' of https://github.com/ramsayleung/rspotify into…
marioortizmanero Aug 16, 2020
cfd4aa6
Merge with master, clean up docs
marioortizmanero Aug 27, 2020
392a751
Documentation polishing
marioortizmanero Aug 27, 2020
918db60
Update changelog
marioortizmanero Aug 27, 2020
0cb81ae
Documentation for the blocking module on release
marioortizmanero Aug 27, 2020
dc43420
Improved changelog wording
marioortizmanero Aug 27, 2020
dd60983
Unnecessary return
marioortizmanero Aug 27, 2020
9ee378b
Use env-file feature for tests
marioortizmanero Aug 27, 2020
087aaf1
Fix 'user_playlist_remove_specific_occurrenes_of_tracks' typo
marioortizmanero Aug 27, 2020
e7d7828
Note typo in the changelog as well
marioortizmanero Aug 27, 2020
a818b0c
Fix cargo check and test
marioortizmanero Aug 27, 2020
7a376f1
Include env-file dependency for examples
marioortizmanero Aug 27, 2020
ad0eece
Revert Vec::new() change
marioortizmanero Aug 27, 2020
170c279
Fix webapp 'rspotify' dependency and upper imports
marioortizmanero Aug 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ failure = "0.1"
lazy_static = "1.0"
log = "0.4"
percent-encoding = "1.0.1"
rand = "0.6.5"
getrandom = "0.1"
reqwest = { version = "0.10", features = ["json", "socks"], default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
17 changes: 11 additions & 6 deletions src/blocking/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Utils function
use chrono::prelude::*;
use rand::distributions::Alphanumeric;
use rand::{self, Rng};
use webbrowser;

use std::collections::HashMap;
Expand All @@ -12,17 +10,24 @@ use std::string::ToString;

use super::oauth2::{SpotifyOAuth, TokenInfo};

use getrandom::getrandom;

static ALPHANUM: &[u8] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".as_bytes();
/// Convert datetime to unix timestampe
pub fn datetime_to_timestamp(elapsed: u32) -> i64 {
let utc: DateTime<Utc> = Utc::now();
utc.timestamp() + i64::from(elapsed)
}
/// Generate `length` random chars
pub fn generate_random_string(length: usize) -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(length)
.collect()
let mut buf = vec![0u8; length];
getrandom(&mut buf).unwrap();
let range = ALPHANUM.len();
return buf
.iter()
.map(|byte| ALPHANUM[*byte as usize % range] as char)
.collect();
}

/// Convert map to `query_string`, for example:
Expand Down
17 changes: 11 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! utils function
use chrono::prelude::*;
use rand::distributions::Alphanumeric;
use rand::{self, Rng};

use std::collections::HashMap;
use std::fmt::Debug;
Expand All @@ -10,6 +8,10 @@ use std::io;
use std::string::ToString;

use super::oauth2::{SpotifyOAuth, TokenInfo};
use getrandom::getrandom;

static ALPHANUM: &[u8] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".as_bytes();

/// convert datetime to unix timestampe
pub fn datetime_to_timestamp(elapsed: u32) -> i64 {
Expand All @@ -18,10 +20,13 @@ pub fn datetime_to_timestamp(elapsed: u32) -> i64 {
}
/// generate `length` random chars
pub fn generate_random_string(length: usize) -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(length)
.collect()
let mut buf = vec![0u8; length];
getrandom(&mut buf).unwrap();
let range = ALPHANUM.len();
return buf
.iter()
.map(|byte| ALPHANUM[*byte as usize % range] as char)
.collect();
}

/// convert map to `query_string`, for example:
Expand Down