• 11 Posts
  • 41 Comments
Joined 1 year ago
cake
Cake day: June 25th, 2023

help-circle

  • I think where I was getting hung up here as I was still thinking of the value of the reference rather than the reference itself. That’s why I brought up Strings, it didn’t make sense that String would automatically implement Copy since they go on the heap. But I see now we’re talking about the pointer reference TO that value.

    Thanks!



  • So, for #1, it is not saying that T implements Copy, it is saying that regardless of what T is, &T implements Copy. This is because, by definition, it is always valid to copy a shared reference, even if T itself is not Copy.

    Got it! this helps a lot, thanks. I think I was indeed thinking of it as some kind of pseudo type and not a type in of itself. I got a little lost in the further explanation, but I really need to spend more time understanding Clone and Copy in general. Thanks!






  • I managed to get this working, but there has to be a better way. How else could I write this?

      pub async fn insert_or_return_user(
            db: &DbConn,
            partial_user: Auth0UserPart,
        ) -> Result {
            let user = users::ActiveModel {
                email: Set(partial_user.email.to_owned()),
                email_verified: Set(partial_user.email_verified.to_owned()),
                auth0_sub: Set(partial_user.sub.to_owned()),
                ..Default::default()
            };
    
            let result = user.clone().insert(db).await;
    
            match result {
                Ok(u) => {
                    println!("{u:#?}");
                    Ok(u.try_into_model().unwrap() as UsersModel)
                }
                Err(error) => {
                    let user = Users::find()
                        .filter(users::Column::Auth0Sub.eq(&partial_user.sub))
                        .one(db)
                        .await?;
    
                    Ok(user.unwrap() as UsersModel)
                }
            }
        }
    






  • nerdbloodOPtoRust*Permanently Deleted*
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 year ago

    I got the response wrong, here’s what I’m using that isn’t working:

    enum NationResponse {
        Nation(Nation),
        People(Vec),
    }
    

    Why the heck can’t I edit the original post after a comment is made?