Struct rustdx::file::day::Day

source ·
pub struct Day {
    pub date: u32,
    pub code: u32,
    pub open: f32,
    pub high: f32,
    pub low: f32,
    pub close: f32,
    pub amount: f32,
    pub vol: u32,
}
Expand description

解析 *.day 文件中的一条日线数据,即其 32 个字节所代表的所有信息。

注意:这个类型只对 *.day 文件进行了初步解析, 所以日期 date 和股票代码 code 都是 u32 类型,

§注意

开启 serde feature 时,此结构体的序列化 (serialize) 时:

  1. date年-月-日 格式
  2. code 为 6 位字符串的股票代码

Fields§

§date: u32§code: u32§open: f32§high: f32§low: f32§close: f32§amount: f32§vol: u32

Implementations§

source§

impl Day

source

pub fn from_bytes(code: u32, arr: &[u8]) -> Self

*.day 文件中获取数据,该文件中,每 32 个字节存储了一根日线数据, 各字节存储数据如下:

字节位置含义解析方式额外处理
00 ~ 03 字节年月日u32见下文
04 ~ 07 字节开盘价u32所解析的数字/100
08 ~ 11 字节最高价u32所解析的数字/100
12 ~ 15 字节最低价u32所解析的数字/100
16 ~ 19 字节收盘价u32所解析的数字/100
20 ~ 23 字节成交额(元)f32/
24 ~ 27 字节成交量(股)u32/
28 ~ 31 字节保留字段//

年月日处理方式:例如对 20210810 结果进行如下处理

年:20210810/10000 = 2021

月:20210810%10000/100 = 8

日:20210810%10000%100 = 10

source

pub fn from_file_into_vec<P: AsRef<Path>>(code: u32, p: P) -> Result<Vec<Day>>

一次性以同步方式读取单个 *.day 文件所有数据,然后转化成 Vec。

source

pub fn date_string(&self) -> String

%Y-%m-%d 格式的日期

source

pub fn ymd_arr(&self) -> [u32; 3]

[年, 月, 日] 格式的日期

source

pub fn ymd(&self) -> NaiveDate

chrono 格式的日期:用于某些序列化或者与时间相关的计算

Trait Implementations§

source§

impl Clone for Day

source§

fn clone(&self) -> Day

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Day

source§

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

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

impl Serialize for Day

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Day

Auto Trait Implementations§

§

impl Freeze for Day

§

impl RefUnwindSafe for Day

§

impl Send for Day

§

impl Sync for Day

§

impl Unpin for Day

§

impl UnwindSafe for Day

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.