Trait Tdx

Source
pub trait Tdx {
    type Item: ?Sized;

    const SEND: &'static [u8];
    const TAG: &'static str;
    const LEN: usize = _;

    // Required methods
    fn send(&mut self) -> &[u8] ;
    fn parse(&mut self, response: Vec<u8>);
    fn result(&self) -> &Self::Item;

    // Provided methods
    fn recv(&mut self, tcp: &mut Tcp) -> Result<Vec<u8>> { ... }
    fn recv_parsed(&mut self, tcp: &mut Tcp) -> Result<&Self::Item> { ... }
}

Required Associated Constants§

Source

const SEND: &'static [u8]

待发送的字节。所有发送请求的字节由两部分组成:

  1. 固定的默认字节(基本为前半段字节)
  2. 查询所需的变化的字节(基本为后半段字节)

Tdx::SEND 的作用为默认有效的字节,即发送字节之后会正常响应且数据可以解析, 但是并不保证每次响应的数据完全一致。 比如请求日线时发送字节在当天收盘后是不变的,次日交易日请求得到的数据则可能改变。

如果发送请求的字节有误,则无法得到响应 (比如设置了读取超时,无响应情况下会得到: WouldBlock error)。

字节具体的含义见 Implementor 的 Tdx trait 部分的 SEND 文档。

Source

const TAG: &'static str

描述此次 tcp 连接的用途,目前用于记录日志。

Provided Associated Constants§

Source

const LEN: usize = _

发送的字节的长度。每种请求所发送的字节长度是已知的。默认为 Tdx::SEND 的长度。

Required Associated Types§

Required Methods§

Source

fn send(&mut self) -> &[u8]

真正发送的字节。

Source

fn parse(&mut self, response: Vec<u8>)

解析响应的字节。

Source

fn result(&self) -> &Self::Item

解析后的结果。可以是引用,也可以是 owned type 。

Provided Methods§

Source

fn recv(&mut self, tcp: &mut Tcp) -> Result<Vec<u8>>

得到响应的字节。响应的字节长度无法预测。

Source

fn recv_parsed(&mut self, tcp: &mut Tcp) -> Result<&Self::Item>

得到和解析响应的字节,并返回解析的数据。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Tdx for SecurityCount

Source§

const SEND: &'static [u8]

Source§

const TAG: &'static str = "heartbeat"

Source§

type Item = u16

Source§

impl Tdx for SecurityList

Source§

const SEND: &'static [u8]

Source§

const TAG: &'static str = "股票、指数列表"

Source§

type Item = [SecurityListData]

Source§

impl<'a> Tdx for Kline<'a>

Source§

const SEND: &'static [u8]

Source§

const TAG: &'static str = "日线"

Source§

type Item = [KlineData<'a>]

Source§

impl<'a> Tdx for Xdxr<'a>

Source§

const SEND: &'static [u8]

Source§

const TAG: &'static str = "除权除息"

Source§

type Item = [XdxrData]