pub fn str_to_post(post_str: String) -> Option<Post> {
    let post_v: Value = serde_json::from_str(&post_str).unwrap();
    
    let image_url: String = match post_v["node"]["display_url"].as_str() {
        None => "".to_string(),
        Some(u) => u.to_string(),
    };

    // if there isn't any image_url, the whole post is nonexistant, therefore return none
    // also, this is done right after "parsing" image_url, becuase otherwise the unwrap for unix_timestamp would cause panic
    if image_url == "null".to_string() {
        return None;
    }

    let unix_timestamp: i64 = post_v["node"]["taken_at_timestamp"].to_string().parse::<i64>().unwrap();
    let timestamp: String = NaiveDateTime::from_timestamp(unix_timestamp, 0).to_string();

    let caption: Option<String> = match post_v["node"]["edge_media_to_caption"]["edges"][0]["node"]["text"].as_str() {
        None => None,
        Some(c) => Some(c.to_string()),
    };

    Some(Post {
        caption: caption,
        image_url,
        timestamp,
    })
}
/// parse json string to Post struct instance
parse json string to Post struct instance
parse json string to Post struct instance
pub fn str_to_post(post_str: String) -> Option<Post> {
    let post_v: Value = serde_json::from_str(&post_str).unwrap();
    let image_url: String = match post_v["node"]["display_url"].as_str() {
        None => "".to_string(),
        Some(u) => u.to_string(),
    };
    // if there isn't any image_url, the whole post is nonexistant, therefore return none
    // also, this is done right after "parsing" image_url, becuase otherwise the unwrap for unix_timestamp would cause panic
    if image_url == "null".to_string() {
        return None;
    }
    let unix_timestamp: i64 = post_v["node"]["taken_at_timestamp"].to_string().parse::<i64>().unwrap();
    let timestamp: String = NaiveDateTime::from_timestamp(unix_timestamp, 0).to_string();
    let caption: Option<String> = match post_v["node"]["edge_media_to_caption"]["edges"][0]["node"]["text"].as_str() {
        None => None,
        Some(c) => Some(c.to_string()),
    };
    Some(Post {
        caption: caption,
        image_url,
        timestamp,
    })
}
pub fn str_to_post ( post_str : String ) -> Option < Post > { let post_v : Value = serde_json :: from_str ( & post_str ) . unwrap ( ) ; let image_url : String = match post_v [ " " ] [ " " ] . as_str ( ) { None => " " . to_string ( ) , Some ( u ) => u . to_string ( ) , } ; // if there isn't any image_url, the whole post is nonexistant, therefore return none // also, this is done right after "parsing" image_url, becuase otherwise the unwrap for unix_timestamp would cause panic if image_url == " " . to_string ( ) { return None ; } let unix_timestamp : i64 = post_v [ " " ] [ " " ] . to_string ( ) . parse :: < i64 > ( ) . unwrap ( ) ; let timestamp : String = NaiveDateTime :: from_timestamp ( unix_timestamp , 0 ) . to_string ( ) ; let caption : Option < String > = match post_v [ " " ] [ " " ] [ " " ] [ 0 ] [ " " ] [ " " ] . as_str ( ) { None => None , Some ( c ) => Some ( c . to_string ( ) ) , } ; Some ( Post { caption : caption , image_url , timestamp , } ) }
parse json string to Post struct instance
parse json string to Post struct instance
post_str
String
post_str
String