#[repr(C)]pub struct SDS(pub Sds);
Tuple Fields§
§0: Sds
Implementations§
Source§impl SDS
impl SDS
pub fn empty() -> SDS
pub fn new(s: &str) -> SDS
pub fn from_ptr(init: *const u8, initlen: usize) -> SDS
pub fn from_cstr(s: *const u8) -> SDS
pub fn len(&self) -> usize
pub fn as_ptr(&self) -> *const u8
pub fn avail(&self) -> usize
pub fn hdr_size(&self) -> c_int
Sourcepub fn alloc_size(&self) -> usize
pub fn alloc_size(&self) -> usize
Return the total size of the allocation of the specified sds string, including:
- The sds header before the pointer.
- The string.
- The free buffer at the end if any.
- The implicit null term.
Sourcepub fn alloc_ptr(&self) -> *mut c_void
pub fn alloc_ptr(&self) -> *mut c_void
Return the pointer of the actual SDS allocation (normally SDS strings are referenced by the start of the string buffer).
pub fn lower(&mut self)
pub fn upper(&mut self)
pub fn to_str<'a>(&self) -> &'a str
pub fn sds_type(&self) -> c_int
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Modify an sds string in-place to make it empty (zero length). However all the existing buffer is not discarded but set as free space so that next append operations will not require allocations up to the number of bytes previously available.
Sourcepub fn extend(&mut self, addlen: size_t)
pub fn extend(&mut self, addlen: size_t)
Enlarge the free space at the end of the sds string so that the caller is sure that after calling this function can overwrite up to addlen bytes after the end of the string, plus one more byte for nul term.
Note: this does not change the length of the sds string as returned by sdslen(), but only the free buffer space we have.
Sourcepub fn compact(&mut self)
pub fn compact(&mut self)
Reallocate the sds string so that it has no free space at the end. The contained string remains not altered, but next concatenation operations will require a reallocation.
After the call, the passed sds string is no longer valid and all the references must be substituted with the new pointer returned by the call.
Sourcepub fn incr_len(&mut self, incr: ssize_t) -> bool
pub fn incr_len(&mut self, incr: ssize_t) -> bool
Increment the sds length and decrements the left free space at the end of the string according to ‘incr’. Also set the null term in the new end of the string.
This function is used in order to fix the string length after the user calls sdsMakeRoomFor(), writes something after the end of the current string, and finally needs to set the new length.
Note: it is possible to use a negative increment in order to right-trim the string.
Usage example:
Using sdsIncrLen() and sdsMakeRoomFor() it is possible to mount the following schema, to cat bytes coming from the kernel to the end of an sds string without copying into an intermediate buffer:
oldlen = sdslen(s); s = sdsMakeRoomFor(s, BUFFER_SIZE); nread = read(fd, s+oldlen, BUFFER_SIZE); … check for nread <= 0 and handle it … sdsIncrLen(s, nread);