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 wsRaw pointer to the C struct
Implementations§
Source§impl<'a> Workspace<'a>
impl<'a> Workspace<'a>
Sourcepub unsafe fn alloc(&mut self, size: NonZeroUsize) -> *mut c_void
pub unsafe fn alloc(&mut self, size: NonZeroUsize) -> *mut c_void
Sourcepub fn contains(&self, data: &[u8]) -> bool
pub fn contains(&self, data: &[u8]) -> bool
Check if a pointer is part of the current workspace
Sourcepub fn allocate(
&mut self,
size: NonZeroUsize,
) -> Result<&'a mut [MaybeUninit<u8>], VclError>
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.
Sourcepub fn allocate_zeroed(
&mut self,
size: NonZeroUsize,
) -> Result<&'a mut [u8], VclError>
pub fn allocate_zeroed( &mut self, size: NonZeroUsize, ) -> Result<&'a mut [u8], VclError>
Allocate [u8; size] array on Workspace, and zero it.
Sourcepub fn copy_blob(
&mut self,
value: impl AsRef<[u8]>,
) -> Result<VCL_BLOB, VclError>
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
Sourcepub fn copy_txt(&mut self, value: impl AsRef<CStr>) -> Result<txt, VclError>
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
Sourcepub fn copy_cstr(
&mut self,
value: impl AsRef<CStr>,
) -> Result<VCL_STRING, VclError>
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
Sourcepub fn copy_bytes_with_null(
&mut self,
src: impl AsRef<[u8]>,
) -> Result<txt, VclError>
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.
Sourcepub fn reserve(&mut self) -> ReservedBuf<'a>
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.