stock-rust 0.1.0

Rust version of stock-api
Documentation
use anyhow::Result as AnyResult;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

pub type Result<T> = AnyResult<T>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Stock {
    pub name: String,
    pub code: String,
    pub now: f64,
    pub low: f64,
    pub high: f64,
    pub percent: f64,
    pub yesterday: f64,
}

impl Stock {
    pub fn default_with_code(code: &str) -> Self {
        Self {
            name: "---".to_string(),
            code: code.to_string(),
            now: 0.0,
            low: 0.0,
            high: 0.0,
            percent: 0.0,
            yesterday: 0.0,
        }
    }
}

#[async_trait]
pub trait StockApi {
    async fn get_stock(&self, code: &str) -> Result<Stock>;
    async fn get_stocks(&self, codes: &[String]) -> Result<Vec<Stock>>;
    async fn search_stocks(&self, key: &str) -> Result<Vec<Stock>>;
}