Skip to main content

exa_async/resources/
search.rs

1use crate::{
2    client::Client,
3    config::Config,
4    error::ExaError,
5    types::search::{SearchRequest, SearchResponse},
6};
7
8/// API resource for the `/search` endpoint
9pub struct Search<'c, C: Config> {
10    client: &'c Client<C>,
11}
12
13impl<'c, C: Config> Search<'c, C> {
14    /// Creates a new Search resource
15    #[must_use]
16    pub const fn new(client: &'c Client<C>) -> Self {
17        Self { client }
18    }
19
20    /// Execute a search query
21    ///
22    /// # Errors
23    ///
24    /// Returns an error if the request fails or the API returns an error.
25    pub async fn create(&self, req: SearchRequest) -> Result<SearchResponse, ExaError> {
26        self.client.post("/search", req).await
27    }
28}
29
30// Add accessor to client
31impl<C: Config> crate::Client<C> {
32    /// Returns the Search API resource
33    #[must_use]
34    pub const fn search(&self) -> Search<'_, C> {
35        Search::new(self)
36    }
37}