[−][src]Struct bumpy_vector::BumpyVector
Represents an instance of a Bumpy Vector
Implementations
impl<'a, T> BumpyVector<T>
[src]
Implement the object.
pub fn new(max_size: usize) -> Self
[src]
Create a new instance of BumpyVector.
The range of the vector goes from 0
to max_size - 1
. If any
elements beyond the end are accessed, an error will be returned.
pub fn insert(&mut self, entry: BumpyEntry<T>) -> Result<(), &'static str>
[src]
Insert a new entry.
Return
Returns Ok(())
if successfully inserted. If it would overlap another
entry or exceed max_size
, return Err(&str)
with a descriptive error
string.
Size must be at least 1.
Example
use bumpy_vector::{BumpyEntry, BumpyVector}; // Create a 10-byte `BumpyVector` let mut v: BumpyVector<&str> = BumpyVector::new(10); // Insert a 2-byte value starting at index 5 (using BumpyEntry directly) assert!(v.insert(BumpyEntry { entry: "hello", index: 5, size: 2 }).is_ok()); // Insert another 2-byte value starting at index 7 (using into()) assert!(v.insert(("hello", 7, 2).into()).is_ok()); // Fail to insert a value that would overlap the first assert!(v.insert(("hello", 4, 2).into()).is_err()); // Fail to insert a value that would overlap the second assert!(v.insert(("hello", 6, 1).into()).is_err()); // Fail to insert a value that would go out of bounds assert!(v.insert(("hello", 100, 1).into()).is_err());
pub fn remove(&mut self, index: usize) -> Option<BumpyEntry<T>>
[src]
Remove and return the entry at index
.
Note that the entry doesn't necessarily need to start at index
,
just overlap it.
Example
use bumpy_vector::BumpyVector; // Create a 10-byte `BumpyVector` let mut v: BumpyVector<&str> = BumpyVector::new(10); // Insert some data v.insert(("hello", 0, 4).into()).unwrap(); v.insert(("hello", 4, 4).into()).unwrap(); assert!(v.remove(0).is_some()); assert!(v.remove(0).is_none()); assert!(v.remove(6).is_some()); assert!(v.remove(6).is_none());
pub fn remove_range(
&mut self,
index: usize,
length: usize
) -> Vec<BumpyEntry<T>>
[src]
&mut self,
index: usize,
length: usize
) -> Vec<BumpyEntry<T>>
Remove and return a range of entries.
Example
use bumpy_vector::BumpyVector; // Create a 10-byte `BumpyVector` let mut v: BumpyVector<&str> = BumpyVector::new(10); // Insert some data v.insert(("hello", 0, 4).into()).unwrap(); v.insert(("hello", 4, 4).into()).unwrap(); assert_eq!(2, v.remove_range(0, 10).len()); assert_eq!(0, v.remove_range(0, 10).len());
pub fn get(&self, index: usize) -> Option<&BumpyEntry<T>>
[src]
Return a reference to an entry at the given index.
Note that the entry doesn't necessarily need to start at the given index, it can simply be contained there.
Example
use bumpy_vector::BumpyVector; // Create a 10-byte `BumpyVector` let mut v: BumpyVector<&str> = BumpyVector::new(10); // Insert some data v.insert(("hello", 0, 4).into()).unwrap(); assert!(v.get(0).is_some()); assert!(v.get(1).is_some()); assert!(v.get(2).is_some()); assert!(v.get(3).is_some()); assert!(v.get(4).is_none()); assert!(v.get(5).is_none()); assert_eq!("hello", v.get(0).unwrap().entry); assert_eq!("hello", v.get(1).unwrap().entry); assert_eq!("hello", v.get(2).unwrap().entry); assert_eq!("hello", v.get(3).unwrap().entry);
pub fn get_mut(&mut self, index: usize) -> Option<&mut BumpyEntry<T>>
[src]
Return a mutable reference to an entry at the given index.
Example
use bumpy_vector::BumpyVector; // Create a small BumpyVector let mut h: BumpyVector<String> = BumpyVector::new(10); // Insert a string to the start h.insert((String::from("hello"), 0, 2).into()).unwrap(); assert_eq!("hello", h.get(0).unwrap().entry); assert_eq!("hello", h.get(1).unwrap().entry); // Get a mutable reference to the string let s = h.get_mut(1).unwrap(); // Modify it somehow s.entry.make_ascii_uppercase(); // Verify it's changed assert_eq!("HELLO", h.get(0).unwrap().entry); assert_eq!("HELLO", h.get(1).unwrap().entry);
pub fn get_exact(&self, index: usize) -> Option<&BumpyEntry<T>>
[src]
Return a reference to an entry that starts at the given index.
Example
use bumpy_vector::BumpyVector; // Create a 10-byte `BumpyVector` let mut v: BumpyVector<&str> = BumpyVector::new(10); // Insert some data v.insert(("hello", 0, 4).into()).unwrap(); assert!(v.get_exact(0).is_some()); assert!(v.get_exact(1).is_none()); assert!(v.get_exact(2).is_none()); assert!(v.get_exact(3).is_none()); assert!(v.get_exact(4).is_none()); assert!(v.get_exact(5).is_none()); assert_eq!("hello", v.get_exact(0).unwrap().entry);
pub fn get_exact_mut(&mut self, index: usize) -> Option<&mut BumpyEntry<T>>
[src]
Return a mutable reference to an entry at exactly the given index.
Example
use bumpy_vector::BumpyVector; // Create a small BumpyVector let mut h: BumpyVector<String> = BumpyVector::new(10); // Insert a string to the start h.insert((String::from("hello"), 0, 2).into()).unwrap(); assert_eq!("hello", h.get_exact(0).unwrap().entry); assert!(h.get_exact(1).is_none()); // Get a mutable reference to the string let s = h.get_exact_mut(0).unwrap(); // Modify it somehow s.entry.make_ascii_uppercase(); // Verify it's changed assert_eq!("HELLO", h.get_exact(0).unwrap().entry); assert!(h.get_exact(1).is_none());
pub fn get_range(&self, start: usize, length: usize) -> Vec<&BumpyEntry<T>>
[src]
Return a vector of entries within the given range.
Note that the first entry doesn't need to start at the given index it can simply be contained there.
Parameters
start
- The starting index.length
- The length to retrieve.
Example
use bumpy_vector::BumpyVector; // Create a 10-byte `BumpyVector` let mut v: BumpyVector<&str> = BumpyVector::new(10); // Insert some data with a gap in the middle v.insert(("hello", 0, 2).into()).unwrap(); v.insert(("hello", 4, 2).into()).unwrap(); assert_eq!(1, v.get_range(0, 1).len()); assert_eq!(1, v.get_range(0, 2).len()); assert_eq!(1, v.get_range(0, 3).len()); assert_eq!(1, v.get_range(0, 4).len()); assert_eq!(2, v.get_range(0, 5).len());
Panics
Panics if an entry's size is 0. That shouldn't be possible short of tinkering with internal state (most likely modifying serialized data).
pub fn len(&self) -> usize
[src]
Returns the number of entries.
pub fn max_size(&self) -> usize
[src]
Trait Implementations
impl<T: Clone> Clone for BumpyVector<T>
[src]
fn clone(&self) -> BumpyVector<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for BumpyVector<T>
[src]
impl<T: Default> Default for BumpyVector<T>
[src]
fn default() -> BumpyVector<T>
[src]
impl<'a, T> IntoIterator for &'a BumpyVector<T>
[src]
Convert into an iterator.
Naively iterate across all entries, move them into a Vec<_>
, and convert
that vector into an iterator.
type Item = &'a BumpyEntry<T>
The type of the elements being iterated over.
type IntoIter = IntoIter<&'a BumpyEntry<T>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<&'a BumpyEntry<T>>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for BumpyVector<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for BumpyVector<T> where
T: Send,
T: Send,
impl<T> Sync for BumpyVector<T> where
T: Sync,
T: Sync,
impl<T> Unpin for BumpyVector<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for BumpyVector<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,