pgrx_pg_sys::submodules::oids

Struct Oid

Source
pub struct Oid(/* private fields */);
Expand description

An object identifier in Postgres.

This is meant to be understood purely by equality. There is no sensible “order” for Oids.

§Notes

Default shall return a sensical Oid, not necessarily a useful one. Currently, this means that it returns the invalid Oid.

Implementations§

Source§

impl Oid

Source

pub const INVALID: Oid = _

Source

pub const unsafe fn from_u32_unchecked(id: u32) -> Oid

👎Deprecated since 0.11.2: safely converts via SPI, use pg_sys::Oid::from(u32)

Generate an Oid from an arbitrary u32.

§Safety

This allows you to create an Oid that Postgres won’t recognize and throw it into Postgres. Don’t.

You should know what kind of object the identifier would imply before creating it. Postgres may sometimes call very different internal functions based on an Oid input. The extension programming interface of Postgres can reach deep, calling functions that assume the caller should be trusted like Postgres would trust itself. Because it is. Postgres tables can also change at runtime, so if an Oid is not a BuiltinOid, what Postgres does based on an Oid can change dynamically.

The existence of this unsafe requirement to create arbitrary Oids does not, itself, constitute a promise any Oid from Postgres or PGRX is guaranteed to be valid or sensical. There are many existing problems in the way of this, for example:

  • Oid includes the guaranteed-wrong values Oid::INVALID
  • Postgres may return arbitrary-seeming Oids, like BuiltinOid::UNKNOWNOID
  • an Oid can arrive in Rust from a table a non-superuser can write
  • PGRX mostly relies on Rust’s type system instead of the dynamic typing of Postgres, thus often deliberately does not bother to remember what OID something had.

So this function is merely a reminder. Even for extensions that work with many Oids, it is not typical to need to create one from an arbitrary u32. Prefer to use a constant, or a BuiltinOid, or to obtain one from querying Postgres, or simply use Oid::INVALID. Marking it as an unsafe fn is an invitation to get an Oid from more trustworthy sources. This includes Oid::INVALID, or BuiltinOid, or by directly calling into Postgres. An unsafe fn is not an officer of the law empowered to indict C programs for felonies, nor cite SQL statements for misdemeanors, nor even truly stop you from foolishness. Even “trustworthy” is meant here in a similar sense to how raw pointers can be “trustworthy”. Often, you should still check if it’s null.

Source

pub const fn from_builtin(id: u32) -> Result<Oid, NotBuiltinOid>

Gets an Oid from a u32 if it is a valid builtin declared by Postgres

Source

pub const fn as_u32(self) -> u32

Trait Implementations§

Source§

impl Clone for Oid

Source§

fn clone(&self) -> Oid

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Oid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Oid

Source§

fn default() -> Oid

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Oid

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<BuiltinOid> for Oid

Source§

fn from(builtin: BuiltinOid) -> Oid

Converts to this type from the input type.
Source§

impl From<Oid> for Datum

Source§

fn from(oid: Oid) -> Self

Converts to this type from the input type.
Source§

impl From<Oid> for PgOid

Source§

fn from(oid: Oid) -> PgOid

Converts to this type from the input type.
Source§

impl From<Oid> for u32

Source§

fn from(oid: Oid) -> u32

Converts to this type from the input type.
Source§

impl From<u32> for Oid

De facto available via SPI

Source§

fn from(word: u32) -> Oid

Converts to this type from the input type.
Source§

impl Hash for Oid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Oid

Source§

fn eq(&self, other: &Oid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Oid

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl SqlTranslatable for Oid

Source§

impl TryFrom<Oid> for BuiltinOid

Source§

type Error = NotBuiltinOid

The type returned in the event of a conversion error.
Source§

fn try_from(oid: Oid) -> Result<BuiltinOid, NotBuiltinOid>

Performs the conversion.
Source§

impl Copy for Oid

Source§

impl Eq for Oid

Source§

impl StructuralPartialEq for Oid

Auto Trait Implementations§

§

impl Freeze for Oid

§

impl RefUnwindSafe for Oid

§

impl Send for Oid

§

impl Sync for Oid

§

impl Unpin for Oid

§

impl UnwindSafe for Oid

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,