Skip to main content

FastArray

Struct FastArray 

Source
pub struct FastArray<T, const LEN: usize> { /* private fields */ }
Expand description

环形数组,适合高频数据,且数据量不大的场景。线程不安全,使用者请控制好访问时机。

  1. 适合高频数据,且数据量不大的场景
  2. 线程不安全,使用者请控制好访问时机
  3. 设计上,push方法会覆盖掉旧数据,且不删除旧数据。find方法会从最新的数据项开始往前找,直到找到满足条件的项为止。 3.1 例如,LEN=10,push了11项,那么第11项会覆盖掉第1项,但第1项仍然存在。find方法会先找第11项,再找第10项…直到找到满足条件的项为止。 3.2 例如,LEN=10,push了9项,那么第1项到第9项都存在。find方法会先找第9项,再找第8项…直到找到满足条件的项为止。 3.3 例如,LEN=10,push了10项,那么第1项到第10项都存在。find方法会先找第10项,再找第9项…直到找到满足条件的项为止。
  4. 适合的场景:例如,某个接口的调用日志,push方法记录每次调用的日志,find方法根据条件找出满足条件的调用日志。

Implementations§

Source§

impl<T, const LEN: usize> FastArray<T, LEN>

Source

pub fn new() -> Self

Source

pub fn push(&self, item_new: T)

添加1项 请控制此方法不可并发访问

Source

pub fn current(&self) -> Option<&T>

当前项

Source

pub fn clear(&self)

请控制此方法不可并发访问

Source

pub fn find<F: FnMut(&T) -> bool>(&self, f: F) -> Option<&T>

Source

pub fn find_vec<F: FnMut(&T) -> bool>(&self, f: F) -> Vec<&T>

Source

pub fn len(&self) -> usize

实际存储的元素数量(最大为 LEN)

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> Iter<'_, T, LEN>

返回迭代器,从最新到最旧的顺序遍历,支持 .rev() 反向遍历

Trait Implementations§

Source§

impl<T: Debug, const LEN: usize> Debug for FastArray<T, LEN>

Source§

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

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

impl<T, const LEN: usize> Default for FastArray<T, LEN>

Source§

fn default() -> Self

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

impl<T, const LEN: usize> Deref for FastArray<T, LEN>

Source§

type Target = UnsafeData<T, LEN>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: Display, const LEN: usize> Display for FastArray<T, LEN>

Source§

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

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

impl<T, const LEN: usize> Index<usize> for FastArray<T, LEN>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize> IndexMut<usize> for FastArray<T, LEN>

Source§

fn index_mut(&mut self, idx: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T, const LEN: usize> IntoIterator for &'a FastArray<T, LEN>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T, LEN>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, const LEN: usize> IntoIterator for FastArray<T, LEN>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, LEN>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, const LEN: usize> !Freeze for FastArray<T, LEN>

§

impl<T, const LEN: usize> !RefUnwindSafe for FastArray<T, LEN>

§

impl<T, const LEN: usize> Send for FastArray<T, LEN>
where T: Send,

§

impl<T, const LEN: usize> Sync for FastArray<T, LEN>
where T: Sync,

§

impl<T, const LEN: usize> Unpin for FastArray<T, LEN>
where T: Unpin,

§

impl<T, const LEN: usize> UnwindSafe for FastArray<T, LEN>
where T: UnwindSafe,

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.