From 8c9f47f97754e7613a18a24c092cb48423778acf Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Tue, 5 Dec 2023 06:45:06 -0800 Subject: [PATCH] Exporting types that were unintentionally sealed --- CHANGELOG.md | 6 +++++ crates/bonsaidb-core/src/schema.rs | 4 ++-- crates/bonsaidb-core/src/schema/collection.rs | 22 ++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 473cff98ff..e5e2aefac8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `bonsaidb::client::Async`/`Blocking` are now exposed. These types are used when building a client. - `bonsaidb::server::Backend::client_authenticated` is now invoked. +- `bonsaidb::core::schema` now exports these types already in-use by + `NamedCollection::entry`: + - `AsyncEntry` + - `Entry` + - `EntryInsert` + - `EntryUpdate` ## v0.5.0 diff --git a/crates/bonsaidb-core/src/schema.rs b/crates/bonsaidb-core/src/schema.rs index 779308632a..e70a237eee 100644 --- a/crates/bonsaidb-core/src/schema.rs +++ b/crates/bonsaidb-core/src/schema.rs @@ -8,8 +8,8 @@ pub mod view; pub use bonsaidb_macros::{Collection, Schema, View, ViewSchema}; pub use self::collection::{ - AsyncEntry, AsyncList, Collection, DefaultSerialization, InsertError, List, Nameable, - NamedCollection, NamedReference, SerializedCollection, + AsyncEntry, AsyncList, Collection, DefaultSerialization, Entry, EntryInsert, EntryUpdate, + InsertError, List, Nameable, NamedCollection, NamedReference, SerializedCollection, }; pub use self::names::{ Authority, CollectionName, InvalidNameError, Name, Qualified, QualifiedName, SchemaName, diff --git a/crates/bonsaidb-core/src/schema/collection.rs b/crates/bonsaidb-core/src/schema/collection.rs index 720632a33e..3314d1e0b9 100644 --- a/crates/bonsaidb-core/src/schema/collection.rs +++ b/crates/bonsaidb-core/src/schema/collection.rs @@ -1721,6 +1721,7 @@ where EU: EntryUpdate + 'a + Unpin, 'name: 'a, { + /// Retrieves the document, if found/inserted. pub fn execute(self) -> Result>, Error> { let Self { name, @@ -1731,9 +1732,9 @@ where .. } = self; if let Some(mut existing) = Col::load(name, connection)? { - if let Some(update) = update { + if let Some(mut update) = update { loop { - update.call(&mut existing.contents); + update.update(&mut existing.contents); match existing.update(connection) { Ok(()) => return Ok(Some(existing)), Err(Error::DocumentConflict(collection, header)) => { @@ -1853,9 +1854,9 @@ where mut retry_limit: usize, ) -> Result>, Error> { if let Some(mut existing) = Col::load_async(name, connection).await? { - if let Some(update) = update { + if let Some(mut update) = update { loop { - update.call(&mut existing.contents); + update.update(&mut existing.contents); match existing.update_async(connection).await { Ok(()) => return Ok(Some(existing)), Err(Error::DocumentConflict(collection, header)) => { @@ -1961,7 +1962,9 @@ where } } +/// A function that is invoked when inserting a document using the entry api. pub trait EntryInsert: Send + Unpin { + /// Returns the contents of the new document. fn call(self) -> Col::Contents; } @@ -1984,19 +1987,22 @@ where } } +/// A function that is invoked when updating a document using the entry api. pub trait EntryUpdate: Send + Unpin where Col: SerializedCollection, { - fn call(&self, doc: &mut Col::Contents); + /// Updates `doc` with modifications to perform before returning the + /// document. + fn update(&mut self, doc: &mut Col::Contents); } impl EntryUpdate for F where - F: Fn(&mut Col::Contents) + Send + Unpin, + F: FnMut(&mut Col::Contents) + Send + Unpin, Col: NamedCollection + SerializedCollection, { - fn call(&self, doc: &mut Col::Contents) { + fn update(&mut self, doc: &mut Col::Contents) { self(doc); } } @@ -2005,7 +2011,7 @@ impl EntryUpdate for () where Col: SerializedCollection, { - fn call(&self, _doc: &mut Col::Contents) { + fn update(&mut self, _doc: &mut Col::Contents) { unreachable!(); } }