Quote ident example#61
Conversation
…gres Also makes the `pg_extend::guard_pg()` function pub instead of pub(crate) so that it can be used by other modules
| @@ -0,0 +1,1810 @@ | |||
| # This file is automatically @generated by Cargo. | |||
| edition = "2018" | ||
|
|
||
| [features] | ||
| pg_allocator = [] |
There was a problem hiding this comment.
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.
technically this is the only thing that needs to be guarded, though no reason to force that.
There was a problem hiding this comment.
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.
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