-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[core] [macros] Add optional support for compact_str #1922
Conversation
I also wasn't able to make |
Never mind that bit about |
Instead of adding support for arbitrary string-wrapper crates, as upgrading to new versions of #[derive(sqlx::Type)]
#[sqlx(transparent, display_fromstr)]
pub struct MyStr(CompactString); And then with some improvements to Alternatively this might also work as a control attribute on |
@abonander that sounds substantially better than what I came up with ;) |
Hi @abonander . I am wondering if the chances for ending up on the stack remain the same for |
@abonander so, trying to use |
@mcronce Snowed in so can't personally check, but did you try using the custom type override as detailed here? https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-a-differentcustom-type |
@CosmicHorrorDev that requires |
This is one of several "small string optimization" crates out there; I use it in particular because it seems to seems to effectively optimize both performance and size, including
Option
. Being able to pull short strings from a database without an extra allocation for each is a nice little win.I wasn't able to make a generic
impl Encode
work (e.g.impl<'q, DB> Encode<'q, DB> for CompactString where DB: Database
) due to lifetime issues without allocating a heapString
temporarily, so I have separate impls for each database.Decode
was no problem, though, and that makes me think I was probably missing something withEncode
...