Struct SDS

Source
#[repr(C)]
pub struct SDS(pub Sds);

Tuple Fields§

§0: Sds

Implementations§

Source§

impl SDS

Source

pub fn empty() -> SDS

Source

pub fn new(s: &str) -> SDS

Source

pub fn from_ptr(init: *const u8, initlen: usize) -> SDS

Source

pub fn from_cstr(s: *const u8) -> SDS

Source

pub fn len(&self) -> usize

Source

pub fn as_ptr(&self) -> *const u8

Source

pub fn avail(&self) -> usize

Source

pub fn hdr_size(&self) -> c_int

Source

pub fn alloc_size(&self) -> usize

Return the total size of the allocation of the specified sds string, including:

  1. The sds header before the pointer.
  2. The string.
  3. The free buffer at the end if any.
  4. The implicit null term.
Source

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

Source

pub fn lower(&mut self)

Source

pub fn upper(&mut self)

Source

pub fn to_str<'a>(&self) -> &'a str

Source

pub fn sds_type(&self) -> c_int

Source

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.

Source

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.

Source

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.

Source

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);

Source

pub fn incr_len_dangerously(&mut self, incr: ssize_t) -> bool

Trait Implementations§

Source§

impl Clone for SDS

Source§

fn clone(&self) -> Self

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 SDS

Source§

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

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

impl Default for SDS

Source§

fn default() -> Self

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

impl Display for SDS

Source§

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

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

impl Drop for SDS

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Ord for SDS

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SDS

Source§

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

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

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

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

impl PartialOrd for SDS

Source§

fn partial_cmp(&self, other: &SDS) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for SDS

Auto Trait Implementations§

§

impl Freeze for SDS

§

impl RefUnwindSafe for SDS

§

impl !Send for SDS

§

impl !Sync for SDS

§

impl Unpin for SDS

§

impl UnwindSafe for SDS

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.