Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion preprocessed_openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
x-rust-generic-parameter: 'D: for<''de> serde::Deserialize<''de> + Serialize'
x-rust-generic-parameter: 'D: for<''de> serde::Deserialize<''de>'
x-rust-return-type: models::SearchResult<D>
x-rust-has-lifetime: true
/synonym_sets:
Expand Down
9 changes: 5 additions & 4 deletions typesense/src/client/collection/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

use crate::{Client, Error, execute_wrapper, traits};
use ::std::borrow::Cow;
use serde::{Serialize, de::DeserializeOwned};
use serde::de::DeserializeOwned;
use typesense_codegen::apis::documents_api;

/// Provides methods for interacting with a single document within a specific Typesense collection.
///
/// This struct is created by calling a method like `client.collection_schemaless("collection_name").document("document_id")`
/// or `client.collection::<MyType>().document("document_id")`.
/// The generic `D` represents the shape of the document and must implement `Serialize` and `DeserializeOwned`.
/// The generic `D` represents the shape of the document and must implement `DeserializeOwned`.
/// Write operations require `D: Document`, which additionally requires `Serialize`.
/// If `D` is not specified, it defaults to `serde_json::Value` for schemaless interactions.
pub struct Document<'d, D = serde_json::Value>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
client: &'d Client,
collection_name: &'d str,
Expand All @@ -27,7 +28,7 @@ where

impl<'d, D> Document<'d, D>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
/// Creates a new `Document` instance for a specific document ID.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions typesense/src/client/collection/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
traits,
};
use ::std::borrow::Cow;
use serde::{Serialize, de::DeserializeOwned};
use serde::de::DeserializeOwned;
use typesense_codegen::{
apis::documents_api,
models::{
Expand All @@ -25,7 +25,7 @@ use typesense_codegen::{
/// `D` will be `MyType`.
pub struct Documents<'d, D = serde_json::Value>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
client: &'d Client,
collection_name: &'d str,
Expand All @@ -34,7 +34,7 @@ where

impl<'d, D> Documents<'d, D>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
/// Creates a new `Documents` instance.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions typesense/src/client/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ mod documents;

use crate::{Client, Error, execute_wrapper};
use ::std::borrow::Cow;
use serde::{Serialize, de::DeserializeOwned};
use serde::de::DeserializeOwned;
use typesense_codegen::{apis::collections_api, models};

/// Provides methods for interacting with a Typesense collection.
///
/// This struct is created by calling `client.collection()`.
pub struct Collection<'c, D = serde_json::Value>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
client: &'c Client,
collection_name: Cow<'c, str>,
Expand All @@ -24,7 +24,7 @@ where

impl<'c, D> Collection<'c, D>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
/// Creates a new `Collection` instance.
#[inline]
Expand Down
15 changes: 8 additions & 7 deletions typesense/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
atomic::{AtomicBool, AtomicUsize, Ordering},
},
};
use serde::{Serialize, de::DeserializeOwned};
use serde::de::DeserializeOwned;
use typesense_codegen::apis::{self, configuration};
use web_time::{Duration, Instant};

Expand Down Expand Up @@ -377,7 +377,7 @@
healthcheck_interval: Duration,
#[builder(into, default)]
/// The retry policy for transient network errors on a *single* node.
retry_policy: ClientRetryPolicy,

Check warning on line 380 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`

Check warning on line 380 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`

Check warning on line 380 in typesense/src/client/mod.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, wasm32-unknown-unknown)

unused variable: `retry_policy`
) -> Result<Self, &'static str> {
let is_nearest_node_set = nearest_node.is_some();

Expand Down Expand Up @@ -629,7 +629,8 @@
/// stored in that collection.
///
/// # Type Parameters
/// * `D` - The type of the documents in the collection. It must be serializable and deserializable.
/// * `D` - The type of the documents in the collection. It must implement `DeserializeOwned`.
/// Write operations (e.g. `create`, `upsert`, `update`) additionally require `D: Document`.
///
/// # Arguments
/// * `collection_name` - The name of the collection to interact with.
Expand All @@ -642,17 +643,17 @@
/// # #[cfg(not(target_family = "wasm"))]
/// # {
/// # use typesense::Client;
/// # use serde::{Serialize, Deserialize};
/// # use serde::Deserialize;
/// #
/// # #[derive(Serialize, Deserialize, Debug)]
/// # #[derive(Deserialize, Debug)]
/// # struct Book { id: String, title: String }
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let client = Client::builder()
/// # .nodes(vec!["http://localhost:8108"])
/// # .api_key("xyz")
/// # .build()
/// # .unwrap();
/// // Get a typed handle to the "books" collection
/// // Get a typed handle to the "books" collection (Deserialize is enough for reads)
/// let books_collection = client.collection_named::<Book>("books");
///
/// // Retrieve a single book, it returns `Result<Book, ...>`
Expand All @@ -669,7 +670,7 @@
collection_name: impl Into<Cow<'c, str>>,
) -> Collection<'c, D>
where
D: DeserializeOwned + Serialize,
D: DeserializeOwned,
{
Collection::new(self, collection_name)
}
Expand All @@ -680,7 +681,7 @@
/// stored in that collection.
///
/// # Type Parameters
/// * `D` - The type of the documents in the collection. It must be of trait Document.
/// * `D` - The type of the documents in the collection. It must implement the [`Document`] trait.
///
/// # Example: Working with a strongly-typed collection
///
Expand Down
2 changes: 1 addition & 1 deletion typesense_codegen/src/apis/documents_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ pub async fn multi_search(
}

/// Search for documents in a collection that match the search criteria.
pub async fn search_collection<D: for<'de> serde::Deserialize<'de> + Serialize>(
pub async fn search_collection<D: for<'de> serde::Deserialize<'de>>(
configuration: &configuration::Configuration,
params: &SearchCollectionParams<'_>,
) -> Result<models::SearchResult<D>, Error<SearchCollectionError>> {
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/add_vendor_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn add_vendor_attributes(doc: &mut OpenAPI) -> Result<(), String> {
// Operations
attrs
.operation("/collections/{collectionName}/documents/search", "get")
.generic_parameter("D: for<'de> serde::Deserialize<'de> + Serialize")?
.generic_parameter("D: for<'de> serde::Deserialize<'de>")?
.return_type("models::SearchResult<D>")?;

attrs
Expand Down
Loading