Skip to content
Open
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
21 changes: 10 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ An ODM for MongoDB built on the official <a href="https://github.com/mongodb/mon
</div>
</br>

The primary goal of this project is to provide a simple, sane & predictable interface into MongoDB based on data models. If at any point this system might get in your way, you have direct access to the underlying driver. This project is tested against MongoDB `3.6`, `4.0`, `4.2` & `4.4`.
The primary goal of this project is to provide a simple, sane & predictable interface into MongoDB based on data models. If at any point this system might get in your way, you have direct access to the underlying driver. This project is tested against MongoDB `3.6`, `4.0`, `4.2`, `4.4` & `5.0`.

**GREAT NEWS!** Wither is now based on the official [MongoDB Rust driver](https://github.com/mongodb/mongo-rust-driver). Thanks to advancements in the driver, Wither is now fully asynchronous. Simply mirroring the features of the underlying MongoDB driver, Wither supports the following runtimes:
- `tokio-runtime` (default) activates [the tokio runtime](tokio.rs/).
Expand Down
12 changes: 5 additions & 7 deletions wither/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@ use std::task::{Context, Poll};

use futures::stream::Stream;
use mongodb::Cursor;
use serde::de::DeserializeOwned;

use crate::error::{Result, WitherError};
use crate::Model;

/// A cursor of model documents.
pub struct ModelCursor<T: DeserializeOwned + Unpin + Send + Sync> {
pub struct ModelCursor<T: Model> {
cursor: Cursor<T>,
marker: std::marker::PhantomData<T>,
}

impl<T: Model + DeserializeOwned + Unpin + Send + Sync> ModelCursor<T> {
impl<T: Model> ModelCursor<T> {
pub(crate) fn new(cursor: Cursor<T>) -> Self {
Self { cursor, marker: std::marker::PhantomData }
Self { cursor }
}
}

// Impl Unpin on this container as we do not care about this container staying pinned,
// only the underlying `Cursor` needs to remain pinned while we poll from this vantage point.
impl<T: DeserializeOwned + Unpin + Send + Sync> Unpin for ModelCursor<T> {}
impl<T: Model> Unpin for ModelCursor<T> {}

impl<T: Model + DeserializeOwned + Unpin + Send + Sync> Stream for ModelCursor<T> {
impl<T: Model> Stream for ModelCursor<T> {
type Item = Result<T>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down
1 change: 1 addition & 0 deletions wither/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const MONGO_DIFF_INDEX_BLACKLIST: [&str; 3] = ["v", "ns", "key"];
#[async_trait]
pub trait Model
where
// Unpin + Send + Sync are required to create a mongodb Cursor for the Model.
Self: Serialize + DeserializeOwned + Unpin + Send + Sync,
{
/// The name of the collection where this model's data is stored.
Expand Down