Skip to main content

exa_async/resources/
search.rs

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