Trait pgx::datum::WithTypeIds
source · [−]pub trait WithTypeIds {
const ITEM_ID: Lazy<TypeId>;
const OPTION_ID: Lazy<Option<TypeId>>;
const VEC_ID: Lazy<Option<TypeId>>;
const VEC_OPTION_ID: Lazy<Option<TypeId>>;
const OPTION_VEC_ID: Lazy<Option<TypeId>>;
const OPTION_VEC_OPTION_ID: Lazy<Option<TypeId>>;
const ARRAY_ID: Lazy<Option<TypeId>>;
const OPTION_ARRAY_ID: Lazy<Option<TypeId>>;
const VARLENA_ID: Lazy<Option<TypeId>>;
fn register_with_refs(map: &mut HashSet<RustSqlMapping>, single_sql: String)
where
Self: 'static,
{ ... }
fn register_sized_with_refs(
_map: &mut HashSet<RustSqlMapping>,
_single_sql: String
)
where
Self: 'static,
{ ... }
fn register_sized(_map: &mut HashSet<RustSqlMapping>, _single_sql: String)
where
Self: 'static,
{ ... }
fn register_varlena_with_refs(
_map: &mut HashSet<RustSqlMapping>,
_single_sql: String
)
where
Self: 'static,
{ ... }
fn register_varlena(_map: &mut HashSet<RustSqlMapping>, _single_sql: String)
where
Self: 'static,
{ ... }
fn register_array_with_refs(
_map: &mut HashSet<RustSqlMapping>,
_single_sql: String
)
where
Self: 'static,
{ ... }
fn register_array(_map: &mut HashSet<RustSqlMapping>, _single_sql: String)
where
Self: 'static,
{ ... }
fn register(set: &mut HashSet<RustSqlMapping>, single_sql: String)
where
Self: 'static,
{ ... }
}
Expand description
A type which can have it’s core::any::TypeId
s registered for Rust to SQL mapping.
An example use of this trait:
use pgx::{
datum::{WithTypeIds, WithSizedTypeIds, WithArrayTypeIds, WithVarlenaTypeIds, PgVarlena},
Array, PostgresType, StringInfo, JsonInOutFuncs, pg_extern, pg_sys, IntoDatum, pg_guard,
};
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PostgresType)]
struct Treat<'a> { best_part: &'a str, };
let mut mappings = Default::default();
let treat_string = stringify!(Treat).to_string();
<Treat<'static> as WithTypeIds>::register_with_refs(&mut mappings, treat_string.clone());
assert!(mappings.iter().any(|x| x.id == core::any::TypeId::of::<Treat<'static>>()));
This trait uses the fact that inherent implementations are a higher priority than trait implementations.