[−][src]Struct framering::FramedRing
A ring buffer which exposes operations via 'frames'.
Implementations
impl<T, Cap: Capacity> FramedRing<T, Cap>
[src]
pub fn new() -> Self
[src]
Creates a new FramedRing with the default Cap size
Example
let mut ring = FramedRing::<(), LinearCapacity>::new();
pub fn with_capacity(c: Cap) -> Self
[src]
Creates a new FramedRing with the given capacity
Example
let mut ring = FramedRing::<i32, LinearCapacity>::with_capacity(LinearCapacity{cap: 32}); assert_eq!(ring.capacity(), 32);
pub fn frame<'ring>(&'ring self) -> RingFrameMut<'ring, T, Cap>
[src]
Creates a new root frame. Panics if this is called when another frame is still in scope
Example
let mut ring = FramedRing::<i32, LinearCapacity>::new(); let mut frame = ring.frame(); frame.push(1);
pub fn frame_reserve<'ring>(
&'ring self,
frame_capacity: usize
) -> RingFrameMut<'ring, T, Cap>
[src]
&'ring self,
frame_capacity: usize
) -> RingFrameMut<'ring, T, Cap>
Creates a new root frame with the given capacity for inserting elements. Panics if this is called when another frame is still in scope
Example
let mut ring = FramedRing::<i32, LinearCapacity>::new(); let mut frame = ring.frame_reserve(4); assert_eq!(ring.capacity(), 5); frame.push(1);
pub fn try_promote<'ring>(
&'ring self,
frame: RingFrame<'ring, T, Cap>
) -> Result<RingFrameMut<'ring, T, Cap>, RingFrame<'ring, T, Cap>>
[src]
&'ring self,
frame: RingFrame<'ring, T, Cap>
) -> Result<RingFrameMut<'ring, T, Cap>, RingFrame<'ring, T, Cap>>
Tries to promote a given frame to a mutable frame which can be appended to. Returns Ok with the new mutable frame if the passed frame could be promoted or returns Err with the passed frame if unable.
Example
let mut ring = FramedRing::<i32, LinearCapacity>::new(); let mut frame = ring.frame(); let (frame_ro, frame2) = frame.next(); let (frame2_ro, frame3) = frame2.next(); drop(frame3); assert!(ring.try_promote(frame_ro).is_err()); assert!(ring.try_promote(frame2_ro).is_ok());
pub fn promote<'ring>(
&'ring self,
frame: RingFrame<'ring, T, Cap>
) -> RingFrameMut<'ring, T, Cap>
[src]
&'ring self,
frame: RingFrame<'ring, T, Cap>
) -> RingFrameMut<'ring, T, Cap>
Promotes a given frame, or panics if passed frame is not able to be promoted
Errors
Panics if the passed frame ring is unable to be promoted for whatever reason.
Example
let mut ring = FramedRing::<i32, LinearCapacity>::new(); let mut frame = ring.frame(); let (frame_ro, frame2) = frame.next(); drop(frame2); ring.promote(frame_ro);
pub fn capacity(&self) -> usize
[src]
Returns the current capacity of the entire ring
Example
let mut ring = FramedRing::<i32, LinearCapacity>::with_capacity(LinearCapacity{cap: 32}); assert_eq!(ring.capacity(), 32);
pub fn size(&self) -> usize
[src]
Returns the used capacity of the entire ring. Counts headers as well as elements which may have been dropped but not free to be used again yet.
About the only use for this is for understanding used capacity.
Examples
let mut ring = FramedRing::<i32, LinearCapacity>::new(); let mut frame = ring.frame(); frame.push(1); // Header + element assert_eq!(ring.size(), 2);
let mut ring = FramedRing::<i32, LinearCapacity>::new(); let mut frame = ring.frame(); frame.push(1); let (frame_ro, mut frame2) = frame.next(); frame2.push(1); let (frame2_ro, mut frame3) = frame2.next(); frame3.push(1); assert_eq!(ring.size(), 6); drop(frame2_ro); assert_eq!(ring.size(), 6); drop(frame_ro); assert_eq!(ring.size(), 2);
Trait Implementations
Auto Trait Implementations
impl<T, Cap> !RefUnwindSafe for FramedRing<T, Cap>
[src]
impl<T, Cap> !Send for FramedRing<T, Cap>
[src]
impl<T, Cap> !Sync for FramedRing<T, Cap>
[src]
impl<T, Cap> Unpin for FramedRing<T, Cap> where
Cap: Unpin,
[src]
Cap: Unpin,
impl<T, Cap> UnwindSafe for FramedRing<T, Cap> where
Cap: UnwindSafe,
T: RefUnwindSafe,
[src]
Cap: UnwindSafe,
T: RefUnwindSafe,
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,
pub 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, 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.
pub 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>,