TushareRequest

Struct TushareRequest 

Source
pub struct TushareRequest {
    pub api_name: Api,
    pub params: HashMap<String, String>,
    pub fields: Vec<String>,
}
Expand description

Tushare API request structure

Supports flexible string type usage, allowing direct use of string literals and String variables

Fields§

§api_name: Api§params: HashMap<String, String>§fields: Vec<String>

Implementations§

Source§

impl TushareRequest

Source

pub fn new<K, V, F, P, Fs>(api_name: Api, params: P, fields: Fs) -> Self
where K: Into<String>, V: Into<String>, F: Into<String>, P: IntoIterator<Item = (K, V)>, Fs: IntoIterator<Item = F>,

Create a new TushareRequest

Examples found in repository?
examples/custom_type_example.rs (lines 119-129)
111async fn main() -> Result<(), Box<dyn std::error::Error>> {
112    // Set up logging
113    env_logger::init();
114    
115    // Create client from environment variable
116    let client = TushareClient::from_env()?;
117    
118    // Create request for daily stock data
119    let request = TushareRequest::new(
120        Api::Daily,
121        params![
122            "ts_code" => "000001.SZ",
123            "start_date" => "20240101",
124            "end_date" => "20240131"
125        ],
126        fields![
127            "ts_code", "trade_date", "open", "high", "low", "close", "vol", "amount"
128        ]
129    );
130    
131    println!("Fetching daily stock data with custom Decimal types...");
132    
133    // Call API and get typed response with automatic conversion
134    let stock_prices: TushareEntityList<StockPrice> = client.call_api_as(request).await?;
135    
136    println!("Retrieved {} stock price records", stock_prices.len());
137    println!("Has more data: {}", stock_prices.has_more());
138    println!("Total count: {}", stock_prices.count());
139    
140    // Display first few records
141    for (i, price) in stock_prices.iter().take(5).enumerate() {
142        println!("\nRecord {}:", i + 1);
143        println!("  Stock Code: {}", price.ts_code);
144        println!("  Trade Date: {}", price.trade_date);
145        println!("  Open Price: {}", price.open_price);
146        println!("  High Price: {}", price.high_price);
147        println!("  Low Price: {}", price.low_price);
148        println!("  Close Price: {}", price.close_price);
149        
150        if let Some(vol) = &price.volume {
151            println!("  Volume: {}", vol);
152        }
153        
154        if let Some(amount) = &price.amount {
155            println!("  Amount: {}", amount);
156        }
157    }
158    
159    Ok(())
160}
Source

pub fn with_str_params<const N: usize>( api_name: Api, params: [(&str, &str); N], fields: &[&str], ) -> Self

Create parameters from string literals

Source

pub fn add_param<K: Into<String>, V: Into<String>>( self, key: K, value: V, ) -> Self

Add parameter

Source

pub fn add_field<F: Into<String>>(self, field: F) -> Self

Add field

Trait Implementations§

Source§

impl Clone for TushareRequest

Source§

fn clone(&self) -> TushareRequest

Returns a duplicate 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 TushareRequest

Source§

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

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

impl<'de> Deserialize<'de> for TushareRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TushareRequest

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 TryFrom<&&str> for TushareRequest

Source§

type Error = TushareError

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

fn try_from(value: &&str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&String> for TushareRequest

Source§

type Error = TushareError

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

fn try_from(value: &String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&TushareRequest> for TushareRequest

Source§

type Error = Infallible

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

fn try_from(value: &TushareRequest) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for TushareRequest

Source§

type Error = TushareError

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for TushareRequest

Source§

type Error = TushareError

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

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

Source§

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,