prisma-client-rust icon indicating copy to clipboard operation
prisma-client-rust copied to clipboard

Use impl Into for where and setparams, create functions

Open onlycs opened this issue 2 years ago • 7 comments

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

onlycs avatar Oct 05 '23 11:10 onlycs

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 13, 2024 2:50am

vercel[bot] avatar Oct 05 '23 11:10 vercel[bot]

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

Brendonovich avatar Oct 05 '23 14:10 Brendonovich

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 avatar Oct 07 '23 15:10 onlycs

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 avatar Nov 22 '23 21:11 onlycs

@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?

onlycs avatar Dec 19 '23 01:12 onlycs

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.

Brendonovich avatar Dec 28 '23 10:12 Brendonovich

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.

onlycs avatar Mar 21 '24 11:03 onlycs