HighSpeedCache

Struct HighSpeedCache 

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

Implementations§

Source§

impl<T, const LEN: usize> HighSpeedCache<T, LEN>
where T: CacheData,

Source

pub fn with_capacity(_capacity: usize) -> Self

创建一个新的高速缓存,与 Vec 的 with_capacity 方法类似 注意:因为内部已经使用固定大小的数组,参数 capacity 仅用于保持 API 风格一致性

Source

pub fn new() -> Self

Source

pub fn push(&self, item_new: T)

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

Source

pub fn current(&self) -> &T

当前项

Source

pub fn clear(&self)

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

Source

pub fn find_找之前的项( &self, 毫秒数: i64, is_找不到即取最新数据: bool, ) -> Option<&T>

传参:毫秒 如果找不到精确定位的数据, 则返回最新的那条数据

Source

pub fn find_limit<F: Fn(&T, &T) -> bool>( &self, n: i64, is_return_last: bool, compare: F, ) -> T

如果十档或者前封单数据如果出现断档的情况,那么把前一个数据的时间戳改成现在数据并且减10毫秒 下次找数据时可以直接找到这一条 找到范围内最大的值 n: 毫秒数 is_return_last: true; 两秒内最大值找不到, 即找一个最新的数据 compare: 比较两个值, 返回true则使用新的值

TODO: 不要使用补数据的逻辑, 找不到数据即取一个最新的数据

Source

pub fn list_items_len(&self, count: usize) -> Vec<&T>

传参:找多少个

Source

pub fn list_items(&self, 毫秒数: i64) -> Vec<&T>

传参:毫秒

Source§

impl<T, const LEN: usize> HighSpeedCache<T, LEN>
where T: CacheData,

Source

pub fn len(&self) -> usize

返回缓存中的元素数量

Source

pub fn is_empty(&self) -> bool

检查缓存是否为空

Source

pub fn capacity(&self) -> usize

返回缓存的容量(最大可存储元素数)

Source

pub fn get(&self, index: usize) -> Option<&T>

根据索引获取元素的引用

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

获取元素的可变引用

Source

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

返回一个引用迭代器,按从最新到最旧的顺序

Source

pub fn iter_mut(&mut self) -> HighSpeedCacheIterMut<'_, T, LEN>

返回一个可变引用迭代器,按从最新到最旧的顺序

Source

pub fn to_vec(&self) -> Vec<T>
where T: Clone,

转换为 Vec

Trait Implementations§

Source§

impl<T: CacheData, const LEN: usize> Default for HighSpeedCache<T, LEN>

Source§

fn default() -> Self

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

impl<T, const LEN: usize> Deref for HighSpeedCache<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, const LEN: usize> Index<usize> for HighSpeedCache<T, LEN>
where T: CacheData,

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T, const LEN: usize> IndexMut<usize> for HighSpeedCache<T, LEN>
where T: CacheData,

Source§

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

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

impl<'a, T, const LEN: usize> IntoIterator for &'a HighSpeedCache<T, LEN>
where T: CacheData,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = HighSpeedCacheIter<'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<'a, T, const LEN: usize> IntoIterator for &'a mut HighSpeedCache<T, LEN>
where T: CacheData,

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = HighSpeedCacheIterMut<'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 HighSpeedCache<T, LEN>
where T: CacheData + Clone,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = HighSpeedCacheIntoIter<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 HighSpeedCache<T, LEN>

§

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

§

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

§

impl<T, const LEN: usize> Sync for HighSpeedCache<T, LEN>
where T: Sync + Send,

§

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

§

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

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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
§

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

§

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
§

impl<T, U> TryFrom<U> for T
where 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>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.