Replies: 2 comments
-
To set the low bar of doing it by hand each time as easily as possible: impl From<&Slot> for i32 {
fn from(slot: &Slot) -> Self {
slot.0
}
}
// Then every time you need it:
Into::<i32>::into(slot)
// Or
let slot_i32: i32 = slot.into(); Somehow although the macro will complain it expects an i32, that isn't enough to simply write |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ah of course one could also make the newtype value struct Slot(pub i32);
// then everywhere do
slot.0 Although again, looking for ways to do it which don't require the caller to do something every time. If none exist, suggestions for what might be PRd into sqlx. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
From the docs it seems one can use a newtype with sqlx. With no further qualifications.
Full section here
Writing something like the following:
Fails with error:
Unless I'm misunderstanding, the derive macro doesn't work when used in combinations with macros. For one I'd propose the docs are updated (happy to PR) to avoid others running into the same confusion.
But I feel this isn't the first time I'm wrestling with the query macros when what I want is fairly simple and clear: I have something, it is not a Rust type which sqlx defined a Postgres encoder and decoder for, but it may be trivially converted to such.
Do others agree and perhaps have ideas for how sqlx could support this?
Lacking any good suggestions, what are the best ways people have found to appease sqlx, preferably in a way where the caller doesn't have to do something each time, but an implementation is provided instead?
Beta Was this translation helpful? Give feedback.
All reactions