- Notifications
You must be signed in to change notification settings - Fork516
Boxed owned query parameters w/ impl for From<T>#859
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
- Box<dyn ToSql + Sync>- Box<dyn ToSql + Sync + Send>
2c9b9a6
tof9fd5ce
Comparefnfrom(to_sql:T) ->Self{ | ||
Box::new(to_sql) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We could also add impl for Sync only, although I'm not sure if/when it would be needed:
} | |
} | |
impl<'a,T:ToSql +Sync +'a>From<T>forBox<dynToSql +Sync +'a>{ | |
fn from(to_sql:T) ->Self{ | |
Box::new(to_sql) | |
} | |
} | |
I'm not sure I've ever seen this conversion before for other traits. What's the rationale for it? |
elpiel commentedJan 1, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
As mentioned in the comment, this allows you to build a This is necessary in order to build these values e.g. dynamically and I couldn't find any other way to do so. Example:
|
Can't you just call Box::new yourself? |
Maybe I just don't know how to do the casting since I get a type error:
I've also tried the following but then I get an error because of self.campaign_id.map(|s|Box::new(sas_)), |
Without seeing the rest of the code I can't be 100% sure, but one of these should work: |
elpiel commentedJan 3, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Here are links to the playground with 3 non-working examples:
|
sfackler commentedJan 3, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Good point! Didn't think of this 😄 |
Extension of#853 that allows creation of a
Box<dyn ToSql + Send + Sync>
fromT: ToSql