-
Notifications
You must be signed in to change notification settings - Fork 32
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
Quote ident example #61
base: master
Are you sure you want to change the base?
Conversation
…gres Also makes the `pg_extend::guard_pg()` function pub instead of pub(crate) so that it can be used by other modules
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.
I think this is a good example of guard_pg, probably could use some docs explaining things.
@@ -0,0 +1,1810 @@ | |||
# This file is automatically @generated by Cargo. |
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.
delete this file...
edition = "2018" | ||
|
||
[features] | ||
pg_allocator = [] |
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.
I think we'll be getting rid of this feature, FYI.
|
||
unsafe { | ||
guard_pg(|| { | ||
CStr::from_ptr(pg_sys::quote_identifier( |
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.
technically this is the only thing that needs to be guarded, though no reason to force that.
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.
Who "owns" the memory here? PG? Do we need to free the CStr pointer?
|
||
/// The pg_extern attribute wraps the function in the proper functions syntax for C extensions | ||
#[pg_extern] | ||
pub fn rust_quote_ident(value: String) -> String { |
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.
As to taking and returning String
, I've been wondering if we want to better encourage zero-overhead design patterns by only accepting and returning CStr (or CString as necessary, though I think we want to be careful passing owned data from Rust to PG).
If we do that then it becomes the responsibility of the pg-extend user to do the conversations and see the overhead that's being incurred with them.
This is probably a throw-away thing. I'm just looking for feedback on how to use
guard_pg()
.However, I'm definitely happy to make this into a better example and get it merged