Optimize type casting

This commit is contained in:
spikecodes 2021-03-08 18:49:06 -08:00
parent 213babb057
commit bf783c2f3a
No known key found for this signature in database
GPG key ID: 004CECFF9B463BCB
8 changed files with 32 additions and 28 deletions

View file

@ -1,5 +1,5 @@
// CRATES
use crate::utils::*;
use crate::utils::{Post, Preferences, User, error, format_url, param, request, template};
use askama::Template;
use tide::Request;
use time::OffsetDateTime;
@ -55,7 +55,7 @@ async fn user(name: &str) -> Result<User, String> {
// If success, receive JSON in response
Ok(res) => {
// Grab creation date as unix timestamp
let created: i64 = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64;
let created: i64 = res["data"]["created"].as_i64().unwrap_or(0);
// nested_val function used to parse JSON from Reddit APIs
let about = |item| res["data"]["subreddit"][item].as_str().unwrap_or_default().to_string();