Struct pgrx::stringinfo::StringInfo
source · pub struct StringInfo<AllocatedBy: WhoAllocated = AllocatedByRust> { /* private fields */ }Expand description
StringInfoData holds information about an extensible string that is allocated by Postgres’ memory system, but generally follows Rust’s drop semantics
Implementations§
source§impl StringInfo<AllocatedByRust>
impl StringInfo<AllocatedByRust>
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new StringInfo of its default size, allocated in CurrentMemoryContext
Note that Postgres can only represent up to 1 gigabyte of data in a StringInfo
sourcepub fn with_capacity(len: i32) -> Self
pub fn with_capacity(len: i32) -> Self
Construct a new StringInfo, allocated by Postgres in CurrentMemoryContext, ensuring it
has a capacity of the specified len.
Note that Postgres can only represent up to 1 gigabyte of data in a StringInfo
source§impl StringInfo<AllocatedByPostgres>
impl StringInfo<AllocatedByPostgres>
sourcepub unsafe fn from_pg(sid: StringInfo) -> Option<Self>
pub unsafe fn from_pg(sid: StringInfo) -> Option<Self>
Construct a StringInfo from a Postgres-allocated pg_sys::StringInfo.
The backing pg_sys::StringInfo structure will be freed whenever the memory context in which
it was originally allocated is reset.
Safety
This function is unsafe as it cannot confirm the provided pg_sys::StringInfo pointer is
valid
source§impl<AllocatedBy: WhoAllocated> StringInfo<AllocatedBy>
impl<AllocatedBy: WhoAllocated> StringInfo<AllocatedBy>
sourcepub fn push(&mut self, ch: char)
pub fn push(&mut self, ch: char)
Push a Rust character onto the end. A Rust char could be 4 bytes in total, so it
is converted into a String first to ensure unicode correctness
sourcepub fn push_bytes(&mut self, bytes: &[u8])
pub fn push_bytes(&mut self, bytes: &[u8])
Push arbitrary bytes onto the end. Any byte sequence is allowed, including those with embedded NULLs
Panics
This function will panic if the length of bytes is larger than an i32
sourcepub unsafe fn push_raw(&mut self, ptr: *const c_char, len: i32)
pub unsafe fn push_raw(&mut self, ptr: *const c_char, len: i32)
Push the bytes behind a raw pointer of a given length onto the end
Safety
This function is unsafe as we cannot ensure the specified ptr and len arguments
are what you say that are and otherwise in agreement
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the size of the StringInfo back to zero-length. This does/// not* free any
previously-allocated memory
sourcepub fn enlarge(&mut self, needed: i32)
pub fn enlarge(&mut self, needed: i32)
Ensure that this StringInfo is at least needed bytes long
sourcepub fn as_str(&self) -> Result<&str, Utf8Error>
pub fn as_str(&self) -> Result<&str, Utf8Error>
A &str representation.
Errors
If the contained bytes aren’t valid UTF8, a [UTF8Error] is returned. Postgres StringInfo is allowed to contain non-UTF8 byte sequences, so this is a real possibility.
sourcepub fn as_mut_ptr(&self) -> *mut c_char
pub fn as_mut_ptr(&self) -> *mut c_char
A mutable pointer to the backing bytes
sourcepub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
A mutable &[u8] byte slice representation
sourcepub fn into_pg(self) -> *mut StringInfoData
pub fn into_pg(self) -> *mut StringInfoData
Convert this StringInfo into one that is wholly owned and now managed by Postgres
sourcepub fn into_char_ptr(self) -> *const c_char
pub fn into_char_ptr(self) -> *const c_char
Convert this StringInfo into a "char *" that is wholly owned and now managed by Postgres
Trait Implementations§
source§impl Default for StringInfo<AllocatedByRust>
impl Default for StringInfo<AllocatedByRust>
source§impl<AllocatedBy: WhoAllocated> Display for StringInfo<AllocatedBy>
impl<AllocatedBy: WhoAllocated> Display for StringInfo<AllocatedBy>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Convert this StringInfo into a Rust string. This uses String::from_utf8_lossy as
it’s fine for a Postgres StringInfo to contain null bytes and also not even be proper
UTF8.
source§impl<AllocatedBy: WhoAllocated> Drop for StringInfo<AllocatedBy>
impl<AllocatedBy: WhoAllocated> Drop for StringInfo<AllocatedBy>
source§impl From<&[u8]> for StringInfo<AllocatedByRust>
impl From<&[u8]> for StringInfo<AllocatedByRust>
source§impl From<&str> for StringInfo<AllocatedByRust>
impl From<&str> for StringInfo<AllocatedByRust>
source§impl From<String> for StringInfo<AllocatedByRust>
impl From<String> for StringInfo<AllocatedByRust>
source§impl<AllocatedBy: WhoAllocated> From<StringInfo<AllocatedBy>> for &'static CStr
impl<AllocatedBy: WhoAllocated> From<StringInfo<AllocatedBy>> for &'static CStr
source§fn from(val: StringInfo<AllocatedBy>) -> Self
fn from(val: StringInfo<AllocatedBy>) -> Self
source§impl From<Vec<u8, Global>> for StringInfo<AllocatedByRust>
impl From<Vec<u8, Global>> for StringInfo<AllocatedByRust>
source§impl<AllocatedBy: WhoAllocated> Write for StringInfo<AllocatedBy>
impl<AllocatedBy: WhoAllocated> Write for StringInfo<AllocatedBy>
source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl<AllocatedBy> RefUnwindSafe for StringInfo<AllocatedBy>where AllocatedBy: RefUnwindSafe,
impl<AllocatedBy = AllocatedByRust> !Send for StringInfo<AllocatedBy>
impl<AllocatedBy = AllocatedByRust> !Sync for StringInfo<AllocatedBy>
impl<AllocatedBy> Unpin for StringInfo<AllocatedBy>where AllocatedBy: Unpin,
impl<AllocatedBy> UnwindSafe for StringInfo<AllocatedBy>where AllocatedBy: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_mut() into the pipe
function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.