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

Use impl Into for where and setparams, create functions #402

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

onlycs
Copy link

@onlycs onlycs commented Oct 5, 2023

Helpful for when you have a custom type wrapping an i32, for example. You can also borrow strings from structs (no cloning). etc.

@vercel
Copy link

vercel bot commented Oct 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prisma-client-rust ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2023 1:06am

@Brendonovich
Copy link
Owner

I don't have time to review this just yet, but I will say that a lot of PCR's design decisions revolve around function arguments having discrete types rather than generics. This is done so that I can reliably make function return types generic, which I think is more beneficial.
It may work if it's just done for scalar fields, but I'm not certain.

You can also borrow strings from structs (no cloning)

If you're borrowing a string (&String or &str), Into<String> will clone it anyway

@onlycs
Copy link
Author

onlycs commented Oct 7, 2023

I know that it will clone anyways, the point is that the API allows you to borrow it. Tuple struct only containing one type would also be useful, you can just pass it directly (or borrow it), without cluttering the function call with .clone() or .into().

@onlycs
Copy link
Author

onlycs commented Nov 22, 2023

lot of PCR's design decisions revolve around function arguments having discrete types rather than generics

I skipped using impl Into<...> for any generic types because that would just not work

@onlycs
Copy link
Author

onlycs commented Dec 19, 2023

@Brendonovich I believe this PR should be ready to merge, I removed impl Into's for the query params as they would conflict. Could you please review this pr?

@Brendonovich
Copy link
Owner

In in two minds about this:
On one hand, it does offer some dx improvements, especially around string reference types.
On the other hand, it disguises memory allocations and lossy number type conversions, and it introduces more monomorphisation for the compiler to deal with.
Some magic features are nice but drawing that line is hard.

@onlycs
Copy link
Author

onlycs commented Mar 21, 2024

Personally, I prefer a good DX, and impl Into's remove a lot of boilerplate. If you disagree, I'll probably just keep my repo synced with your master and use that in cargo.

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

Successfully merging this pull request may close these issues.

None yet

2 participants