pub trait SymbolSearch: MaybeSend + 'static {
// Required method
fn search(&self, query: SymbolQuery, reply: Reply<Vec<Instrument>>);
}Expand description
Finds instruments for the symbol search dialog, from a source that need not be the feed’s.
The terminal calls search on the UI thread as the user types, and shows the
answer to the newest query only. Return at once and answer once through reply, from any
thread, runtime or browser task; an answer to a query the user has since changed is ignored,
so there is nothing to cancel. The symbol the user picks is loaded from the
Datafeed, so answer with symbols as the feed
knows them. A fixed list of instruments is a service on its own: see the
implementation for Vec<Instrument>.
use egui_charts::data::{FeedError, Reply};
use egui_charts::model::Instrument;
use egui_charts::services::{SymbolQuery, SymbolSearch};
/// Asks a reference-data service from a worker thread.
struct ReferenceData;
impl SymbolSearch for ReferenceData {
fn search(&self, query: SymbolQuery, reply: Reply<Vec<Instrument>>) {
std::thread::spawn(move || reply.send(lookup(&query)));
}
}
/// Stands in for the request to the service.
fn lookup(query: &SymbolQuery) -> Result<Vec<Instrument>, FeedError> {
let apple = Instrument::new("AAPL")
.with_description("Apple Inc.")
.with_exchange("NASDAQ");
Ok([apple].into_iter().skip(query.offset).take(query.limit).collect())
}Required Methods§
Sourcefn search(&self, query: SymbolQuery, reply: Reply<Vec<Instrument>>)
fn search(&self, query: SymbolQuery, reply: Reply<Vec<Instrument>>)
Up to query.limit instruments matching query, best first.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl SymbolSearch for Vec<Instrument>
A fixed list, answered inline: the instruments whose symbol or description contains the text,
ignoring case, and whose type and exchange equal the filters that are set. An instrument whose
symbol equals the text comes first, then those whose symbol starts with it, then the rest, each
group in list order.
impl SymbolSearch for Vec<Instrument>
A fixed list, answered inline: the instruments whose symbol or description contains the text, ignoring case, and whose type and exchange equal the filters that are set. An instrument whose symbol equals the text comes first, then those whose symbol starts with it, then the rest, each group in list order.
fn search(&self, query: SymbolQuery, reply: Reply<Vec<Instrument>>)
Implementors§
impl SymbolSearch for HttpDatafeed
http only.