1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! # Typesense
//!
//! A Rust client library for the Typesense API.
//!
//! This library provides an ergonomic interface for
//! interacting with Typesense. It supports multi-node configuration and WebAssembly.
//!
//! # Examples
//!
//! The following examples demonstrate how to define a collection schema using
//! the Typesense derive macro and create it on the server.
//!
//! ---
//!
//! ### Native (Tokio)
//!
//! This example shows the typical setup for a server-side application using the
//! Tokio runtime. It includes features like connection timeouts and automatic
//! request retries.
//!
//! ```no_run
//! #[cfg(not(target_family = "wasm"))]
//! {
//! use serde::{Deserialize, Serialize};
//! use typesense::{Client, Typesense, ExponentialBackoff, prelude::*};
//! use std::time::Duration;
//!
//! /// A struct representing a company document.
//! #[derive(Typesense, Serialize, Deserialize, Debug)]
//! #[typesense(
//! collection_name = "companies",
//! default_sorting_field = "num_employees"
//! )]
//! struct Company {
//! company_name: String,
//! num_employees: i32,
//! #[typesense(facet)]
//! country: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::builder()
//! .nodes(vec!["http://localhost:8108"])
//! .api_key("xyz")
//! .healthcheck_interval(Duration::from_secs(60))
//! .retry_policy(ExponentialBackoff::builder().build_with_max_retries(3))
//! .build()?;
//!
//! // Create the collection in Typesense
//! let collection = client
//! .collections()
//! .create(Company::collection_schema())
//! .await?;
//!
//! println!("Created collection: {:?}", collection);
//! Ok(())
//! }
//! }
//! ```
//!
//! ---
//!
//! ### WebAssembly (Wasm)
//!
//! This example is tailored for a WebAssembly target.
//! Key difference: Tokio-dependent features like `.retry_policy()` are disabled.
//!
//! ```no_run
//! #[cfg(target_family = "wasm")]
//! {
//! use serde::{Deserialize, Serialize};
//! use typesense::{Client, Typesense, prelude::*};
//! use std::time::Duration;
//! use wasm_bindgen_futures::spawn_local;
//!
//! /// A struct representing a company document.
//! #[derive(Typesense, Serialize, Deserialize, Debug)]
//! #[typesense(
//! collection_name = "companies",
//! default_sorting_field = "num_employees"
//! )]
//! struct Company {
//! company_name: String,
//! num_employees: i32,
//! #[typesense(facet)]
//! country: String,
//! }
//!
//! fn main() {
//! spawn_local(async {
//! let client = Client::builder()
//! .nodes(vec!["http://localhost:8108"])
//! .api_key("xyz")
//! .healthcheck_interval(Duration::from_secs(60))
//! // .retry_policy(...) <-- disabled in Wasm
//! .build()
//! .unwrap();
//!
//! // Create the collection in Typesense
//! match client.collections().create(Company::collection_schema()).await {
//! Ok(collection) => println!("Created collection: {:?}", collection),
//! Err(e) => eprintln!("Error creating collection: {}", e),
//! }
//! });
//! }
//! }
//! ```
pub use ;
pub use *;
pub use typesense_codegen as legacy;
pub use *;