varnish_sys::vcl

Struct Workspace

Source
pub struct Workspace<'a> {
    pub raw: *mut ws,
    /* private fields */
}
Expand description

A workspace object

Used to allocate memory in an efficient manner, data will live there until the end of the transaction and the workspace is wiped, so there’s no need to free the objects living in it.

The workspace is usually a few tens of kilobytes large, don’t be greedy. If you need more space, consider storing your data in a VPriv.

Fields§

§raw: *mut ws

Raw pointer to the C struct

Implementations§

Source§

impl<'a> Workspace<'a>

Source

pub unsafe fn alloc(&mut self, size: NonZeroUsize) -> *mut c_void

Allocate a buffer of a given size.

§Safety

Allocated memory is not initialized.

Source

pub fn contains(&self, data: &[u8]) -> bool

Check if a pointer is part of the current workspace

Source

pub fn allocate( &mut self, size: NonZeroUsize, ) -> Result<&'a mut [MaybeUninit<u8>], VclError>

Allocate [u8; size] array on Workspace. Returns a reference to uninitialized buffer, or an out of memory error.

Source

pub fn allocate_zeroed( &mut self, size: NonZeroUsize, ) -> Result<&'a mut [u8], VclError>

Allocate [u8; size] array on Workspace, and zero it.

Source

pub fn copy_blob( &mut self, value: impl AsRef<[u8]>, ) -> Result<VCL_BLOB, VclError>

Copy any AsRef<[u8]> into a new VCL_BLOB stored in the workspace

Source

pub fn copy_txt(&mut self, value: impl AsRef<CStr>) -> Result<txt, VclError>

Copy any AsRef<CStr> into a new txt stored in the workspace

Source

pub fn copy_cstr( &mut self, value: impl AsRef<CStr>, ) -> Result<VCL_STRING, VclError>

Copy any AsRef<CStr> into a new VCL_STRING stored in the workspace

Source

pub fn copy_bytes_with_null( &mut self, src: impl AsRef<[u8]>, ) -> Result<txt, VclError>

Same as Workspace::copy_blob, copying bytes into Workspace, but treats bytes as a string with an optional NULL character at the end. A NULL is added if it is missing. Returns an error if src contain NULL characters in a non-last position.

Source

pub fn reserve(&mut self) -> ReservedBuf<'a>

Allocate all the free space in the workspace in a buffer that can be reclaimed or truncated later.

Note: don’t assume the slice has been zeroed when it is returned to you, see ReservedBuf::release() for more information.

Trait Implementations§

Source§

impl<'a> Debug for Workspace<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Workspace<'a>

§

impl<'a> RefUnwindSafe for Workspace<'a>

§

impl<'a> !Send for Workspace<'a>

§

impl<'a> !Sync for Workspace<'a>

§

impl<'a> Unpin for Workspace<'a>

§

impl<'a> UnwindSafe for Workspace<'a>

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> 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, 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.