You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I'm working on a foreign data wrapper, I'll need to traverse the plan tree, and de-parse it to extract the information inside it. Currently, I'm manually implementing casting for the types I use:
pubtraitPgNodeExt:PgNode{unsafefnas_restrict_info(&self) -> &pg_sys::RestrictInfo;unsafefnas_op_expr(&self) -> &pg_sys::OpExpr;unsafefnas_var(&self) -> &pg_sys::Var;unsafefnas_const(&self) -> &pg_sys::Const;unsafefnas_relabel_type(&self) -> &pg_sys::RelabelType;unsafefnas_bool_expr(&self) -> &pg_sys::BoolExpr;}impl<T:PgNode>PgNodeExtforT{unsafefnas_restrict_info(&self) -> &pg_sys::RestrictInfo{ifis_type(self, pg_sys::NodeTag_T_RestrictInfo){unsafe{ mem::transmute::<_,&pg_sys::RestrictInfo>(self)}}else{panic!("Not a RestrictInfo");}}unsafefnas_op_expr(&self) -> &pg_sys::OpExpr{ifis_type(self, pg_sys::NodeTag_T_OpExpr){unsafe{ mem::transmute::<_,&pg_sys::OpExpr>(self)}}else{panic!("Not a opexpr");}}unsafefnas_bool_expr(&self) -> &pg_sys::BoolExpr{ifis_type(self, pg_sys::NodeTag_T_BoolExpr){unsafe{ mem::transmute::<_,&pg_sys::BoolExpr>(self)}}else{panic!("Not a boolexpr");}}unsafefnas_var(&self) -> &pg_sys::Var{ifis_type(self, pg_sys::NodeTag_T_Var){unsafe{ mem::transmute::<_,&pg_sys::Var>(self)}}else{panic!("Not a var");}}unsafefnas_const(&self) -> &pg_sys::Const{ifis_type(self, pg_sys::NodeTag_T_Const){unsafe{ mem::transmute::<_,&pg_sys::Const>(self)}}else{panic!("Not a const");}}unsafefnas_relabel_type(&self) -> &pg_sys::RelabelType{ifis_type(self, pg_sys::NodeTag_T_RelabelType){unsafe{ mem::transmute::<_,&pg_sys::RelabelType>(self)}}else{panic!("Not a relabeltype");}}}
I'm wondering if it would be good to build this inside pg_sys? In the build.rs stage we can generate something like:
pub trait PgNodeExt: PgNode {
unsafe fn as_<something>(&self) -> &pg_sys::Something; // for all PgNode types, panic if type mismatch
unsafe fn as_<something>_mut(&mut self) -> &mut pg_sys::Something;
unsafe fn try_as_<something>(&self) -> Option<&pg_sys::Something>; // return None if type mismatch
unsafe fn try_as_<something>_mut(&mut self) -> Option<&mut pg_sys::Something>;
}
Or we can implement it as From and TryFrom.
impl <T: PgNode> From<&T> for <SomeNode> {} // repeat for all pgnodes
impl <T: PgNode> TryFrom<&T> for <SomeNode> {} // repeat for all pgnodes
I can have a try if this sounds like a good idea.
The text was updated successfully, but these errors were encountered:
Do you think it can be 100% machine generated? I've got just enough experience walking the plan tree to think that it could be. My main concern with this is that we don't want to have to maintain handwritten code for this, especially across 5 Postgres versions.
So if you think it can be 100% generated, yeah, give it a shot. We'll most likely accept the patch.
Also note that we've been working on a complete retooling of how we generate bindings. It's not clear to me what impact that'll have to post-processing work such as this, but it'll still be doable -- it may just be that we'll need to rework your patch.
As I'm working on a foreign data wrapper, I'll need to traverse the plan tree, and de-parse it to extract the information inside it. Currently, I'm manually implementing casting for the types I use:
I'm wondering if it would be good to build this inside pg_sys? In the
build.rs
stage we can generate something like:Or we can implement it as
From
andTryFrom
.I can have a try if this sounds like a good idea.
The text was updated successfully, but these errors were encountered: