Struct listpack::Listpack [−][src]
pub struct Listpack { /* fields omitted */ }
Methods
impl Listpack
[src]
impl Listpack
Provides a minimal wrapper to Listpack.
pub fn new() -> Listpack
[src]
pub fn new() -> Listpack
pub fn len(&self) -> u32
[src]
pub fn len(&self) -> u32
Return the number of elements inside the listpack. This function attempts to use the cached value when within range, otherwise a full scan is needed. As a side effect of calling this function, the listpack header could be modified, because if the count is found to be already within the 'numele' header field range, the new value is set.
pub fn size(&self) -> u32
[src]
pub fn size(&self) -> u32
Return the total number of bytes the listpack is composed of.
pub fn get(&self, ele: Element) -> Value
[src]
pub fn get(&self, ele: Element) -> Value
Decodes and returns the entry value of the element.
If the function is called against a badly encoded listpack, so that there
is no valid way to parse it, the function returns like if there was an
integer encoded with value 12345678900000000 +
Similarly, there is no error returned since the listpack normally can be assumed to be valid, so that would be a very high API cost. However a function in order to check the integrity of the listpack at load time is provided, check is_valid().
pub fn get_int(&self, ele: Element) -> i64
[src]
pub fn get_int(&self, ele: Element) -> i64
pub fn get_int_or(&self, ele: Element, default: i64) -> i64
[src]
pub fn get_int_or(&self, ele: Element, default: i64) -> i64
pub fn get_str(&self, ele: Element) -> &str
[src]
pub fn get_str(&self, ele: Element) -> &str
pub fn get_str_or<'a>(&self, ele: Element, default: &'a str) -> &'a str
[src]
pub fn get_str_or<'a>(&self, ele: Element, default: &'a str) -> &'a str
pub fn insert(
&mut self,
value: Value,
p: Element,
action: c_int
) -> Option<Element>
[src]
pub fn insert(
&mut self,
value: Value,
p: Element,
action: c_int
) -> Option<Element>
Insert, delete or replace the specified element 'ele' of length 'len' at the specified position 'p', with 'p' being a listpack element pointer obtained with first(), last(), index(), next(), prev() or seek().
The element is inserted before, after, or replaces the element pointed by 'p' depending on the 'where' argument, that can be BEFORE, AFTER or REPLACE.
If 'ele' is set to NULL, the function removes the element pointed by 'p' instead of inserting one.
Returns None on out of memory or when the listpack total length would exceed the max allowed size of 2^32-1, otherwise the new pointer to the listpack holding the new element is returned (and the old pointer passed is no longer considered valid)
If 'newp' is not NULL, at the end of a successful call '*newp' will be set to the address of the element just added, so that it will be possible to continue an iteration with next() and prev().
For deletion operations ('ele' set to None) 'newp' is set to the next element, on the right of the deleted one, or to NULL if the deleted element was the last one.
pub fn append(&mut self, value: Value)
[src]
pub fn append(&mut self, value: Value)
Append the specified element 'ele' of length 'len' at the end of the listpack. It is implemented in terms of insert(), so the return value is the same as insert().
pub fn replace(&mut self, value: Value, pos: Element)
[src]
pub fn replace(&mut self, value: Value, pos: Element)
pub fn insert_int<V>(
&mut self,
value: V,
p: Element,
action: c_int
) -> Option<Element> where
V: Num,
[src]
pub fn insert_int<V>(
&mut self,
value: V,
p: Element,
action: c_int
) -> Option<Element> where
V: Num,
Insert, delete or replace the specified element 'ele' of length 'len' at the specified position 'p', with 'p' being a listpack element pointer obtained with first(), last(), index(), next(), prev() or seek().
The element is inserted before, after, or replaces the element pointed by 'p' depending on the 'where' argument, that can be BEFORE, AFTER or REPLACE.
If 'ele' is set to NULL, the function removes the element pointed by 'p' instead of inserting one.
Returns None on out of memory or when the listpack total length would exceed the max allowed size of 2^32-1, otherwise the new pointer to the listpack holding the new element is returned (and the old pointer passed is no longer considered valid)
If 'newp' is not NULL, at the end of a successful call '*newp' will be set to the address of the element just added, so that it will be possible to continue an iteration with next() and prev().
For deletion operations ('ele' set to None) 'newp' is set to the next element, on the right of the deleted one, or to NULL if the deleted element was the last one.
pub fn append_int<V>(&mut self, value: V) where
V: Num,
[src]
pub fn append_int<V>(&mut self, value: V) where
V: Num,
Append the specified element 'ele' of length 'len' at the end of the listpack. It is implemented in terms of insert(), so the return value is the same as insert().
pub fn replace_int<V>(&mut self, value: V, pos: Element) where
V: Num,
[src]
pub fn replace_int<V>(&mut self, value: V, pos: Element) where
V: Num,
pub fn insert_str<V>(
&mut self,
value: V,
p: Element,
action: c_int
) -> Option<Element> where
V: Str,
[src]
pub fn insert_str<V>(
&mut self,
value: V,
p: Element,
action: c_int
) -> Option<Element> where
V: Str,
Insert, delete or replace the specified element 'ele' of length 'len' at the specified position 'p', with 'p' being a listpack element pointer obtained with first(), last(), index(), next(), prev() or seek().
The element is inserted before, after, or replaces the element pointed by 'p' depending on the 'where' argument, that can be BEFORE, AFTER or REPLACE.
If 'ele' is set to NULL, the function removes the element pointed by 'p' instead of inserting one.
Returns None on out of memory or when the listpack total length would exceed the max allowed size of 2^32-1, otherwise the new pointer to the listpack holding the new element is returned (and the old pointer passed is no longer considered valid)
If 'newp' is not NULL, at the end of a successful call '*newp' will be set to the address of the element just added, so that it will be possible to continue an iteration with next() and prev().
For deletion operations ('ele' set to None) 'newp' is set to the next element, on the right of the deleted one, or to NULL if the deleted element was the last one.
pub fn append_str<V>(&mut self, value: V) where
V: Str,
[src]
pub fn append_str<V>(&mut self, value: V) where
V: Str,
Append the specified element 'ele' of length 'len' at the end of the listpack. It is implemented in terms of insert(), so the return value is the same as insert().
pub fn replace_str<V>(&mut self, value: V, ele: Element) where
V: Str,
[src]
pub fn replace_str<V>(&mut self, value: V, ele: Element) where
V: Str,
Replace the specified element with the specified value
pub fn delete(&mut self, p: Element) -> Option<Element>
[src]
pub fn delete(&mut self, p: Element) -> Option<Element>
Remove the element pointed by 'p', and return the resulting listpack. If 'newp' is not NULL, the next element pointer (to the right of the deleted one) is returned by reference. If the deleted element was the last one, '*newp' is set to None.
pub fn first(&self) -> Option<Element>
[src]
pub fn first(&self) -> Option<Element>
Return a pointer to the first element of the listpack, or None if the listpack has no elements.
pub fn last(&self) -> Option<Element>
[src]
pub fn last(&self) -> Option<Element>
Return a pointer to the last element of the listpack, or None if the listpack has no elements.
pub fn start(&self) -> Element
[src]
pub fn start(&self) -> Element
pub fn first_or_next(&self, after: Element) -> Option<Element>
[src]
pub fn first_or_next(&self, after: Element) -> Option<Element>
pub fn next(&self, after: Element) -> Option<Element>
[src]
pub fn next(&self, after: Element) -> Option<Element>
/* If 'after' points to an element of the listpack, calling next() will return the pointer to the next element (the one on the right), or None if 'after' already pointed to the last element of the listpack. */
pub fn last_or_prev(&self, after: Element) -> Option<Element>
[src]
pub fn last_or_prev(&self, after: Element) -> Option<Element>
pub fn prev(&self, before: Element) -> Option<Element>
[src]
pub fn prev(&self, before: Element) -> Option<Element>
If 'p' points to an element of the listpack, calling prev() will return the pointer to the previous element (the one on the left), or None if 'before' already pointed to the first element of the listpack.
pub fn seek(&self, index: i64) -> Option<Element>
[src]
pub fn seek(&self, index: i64) -> Option<Element>
Seek the specified element and returns the pointer to the seeked element. Positive indexes specify the zero-based element to seek from the head to the tail, negative indexes specify elements starting from the tail, where -1 means the last element, -2 the penultimate and so forth. If the index is out of range, NULL is returned.