Skip to content

Commit

Permalink
Exporting types that were unintentionally sealed
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Dec 5, 2023
1 parent 7b7de96 commit 8c9f47f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions crates/bonsaidb-core/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 14 additions & 8 deletions crates/bonsaidb-core/src/schema/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ where
EU: EntryUpdate<Col> + 'a + Unpin,
'name: 'a,
{
/// Retrieves the document, if found/inserted.
pub fn execute(self) -> Result<Option<CollectionDocument<Col>>, Error> {
let Self {
name,
Expand All @@ -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)) => {
Expand Down Expand Up @@ -1853,9 +1854,9 @@ where
mut retry_limit: usize,
) -> Result<Option<CollectionDocument<Col>>, 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)) => {
Expand Down Expand Up @@ -1961,7 +1962,9 @@ where
}
}

/// A function that is invoked when inserting a document using the entry api.
pub trait EntryInsert<Col: SerializedCollection>: Send + Unpin {
/// Returns the contents of the new document.
fn call(self) -> Col::Contents;
}

Expand All @@ -1984,19 +1987,22 @@ where
}
}

/// A function that is invoked when updating a document using the entry api.
pub trait EntryUpdate<Col>: 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<F, Col> EntryUpdate<Col> 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);
}
}
Expand All @@ -2005,7 +2011,7 @@ impl<Col> EntryUpdate<Col> for ()
where
Col: SerializedCollection,
{
fn call(&self, _doc: &mut Col::Contents) {
fn update(&mut self, _doc: &mut Col::Contents) {
unreachable!();
}
}
Expand Down

0 comments on commit 8c9f47f

Please sign in to comment.