Skip to content

Quote ident example#61

Open
eeeebbbbrrrr wants to merge 3 commits into
bluejekyll:masterfrom
eeeebbbbrrrr:quote_ident_example
Open

Quote ident example#61
eeeebbbbrrrr wants to merge 3 commits into
bluejekyll:masterfrom
eeeebbbbrrrr:quote_ident_example

Conversation

@eeeebbbbrrrr
Copy link
Copy Markdown

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

…gres

Also makes the `pg_extend::guard_pg()` function pub instead of pub(crate)
so that it can be used by other modules
Copy link
Copy Markdown
Owner

@bluejekyll bluejekyll left a 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.

Comment thread Cargo.lock.orig
@@ -0,0 +1,1810 @@
# This file is automatically @generated by Cargo.
Copy link
Copy Markdown
Owner

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 = []
Copy link
Copy Markdown
Owner

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(
Copy link
Copy Markdown
Owner

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.

Copy link
Copy Markdown
Owner

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 {
Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants