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

Using Trait Into/TryFrom for changing struct between User and FilterUser #2

Open
wrenix opened this issue Mar 19, 2024 · 0 comments
Open

Comments

@wrenix
Copy link

wrenix commented Mar 19, 2024

https://doc.rust-lang.org/stable/rust-by-example/conversion/try_from_try_into.html

Do not implement a function like this:

fn filter_user_record(user: &User) -> FilteredUser {
FilteredUser {
id: user.id.to_string(),
email: user.email.to_owned(),
name: user.name.to_owned(),
photo: user.photo.to_owned(),
role: user.role.to_owned(),
verified: user.verified,
createdAt: user.created_at.unwrap(),
updatedAt: user.updated_at.unwrap(),
}
}

@wrenix wrenix changed the title Using Trait for changing struct between User and FilterUser Using Trait Into/TryFrom for changing struct between User and FilterUser Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant