//! Cotton's published `places` database as a test hears it: one synthetic//! place (an invented-for-tests row, Hyderabad) served by a fake reader//! installed for the process (`served`). A place column or a location pin//! reads it the way the app reads the server.use std::sync::Arc;use cotton_store::published::{self, Answer, Ask, Reader, Unread};use serde_json::{json, Value};/// The version every synthetic answer is read at.pubconst VERSION: &str = "synthetic-1";structSynthetic;fn hyderabad() -> Value { json!({"id": "geonames:1269843", "name": "Hyderabad", "admin1": "40", "country": "IN", "country_name": "India","zone": "Asia/Kolkata", "population": 6809970, "lat": 17.38, "lng": 78.48})}implReaderforSynthetic {fn read(&self, publisher: &str, name: &str, table: &str, ask: &Ask) -> Result<Answer, Unread> {let rows = match (publisher, name, table, ask) { ("cotton", "places", "places", Ask::Ids { ids, .. }) => ids.iter().filter(|id| *id == "geonames:1269843").map(|_| hyderabad()).collect(), ("cotton", "places", "places", Ask::Near { .. }) => vec![hyderabad()], ("cotton", "places", "places", Ask::Search { q, .. }) => {if"hyderabad".starts_with(&q.to_lowercase()) { vec![hyderabad()] } else { vec![] } } _ => vec![], };Ok(Answer { version: VERSION.into(), rows }) }}/// Installed once per test process and never removed, as the app's reader is/// while signed in: every harness reads the same synthetic server.pubfn served() { published::install(Some(Arc::new(Synthetic)));}