Add more #[must_use] attributes (#1828)

This commit is contained in:
Rushmore Mushambi 2023-04-19 10:26:22 +02:00 committed by GitHub
parent 28bd007f72
commit 32352f4bd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 29 additions and 5 deletions

View file

@ -12,6 +12,7 @@ use std::pin::Pin;
/// An authentication future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Authenticate<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) token: Jwt,

View file

@ -11,6 +11,7 @@ use std::pin::Pin;
/// A beginning of a transaction
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Begin<C: Connection> {
pub(super) client: Surreal<C>,
}
@ -34,6 +35,7 @@ where
/// An ongoing transaction
#[derive(Debug)]
#[must_use = "transactions must be committed or cancelled to complete them"]
pub struct Transaction<C: Connection> {
client: Surreal<C>,
}

View file

@ -8,6 +8,7 @@ use std::pin::Pin;
/// A transaction cancellation future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Cancel<C: Connection> {
pub(crate) client: Surreal<C>,
}

View file

@ -8,6 +8,7 @@ use std::pin::Pin;
/// A transaction commit future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Commit<C: Connection> {
pub(crate) client: Surreal<C>,
}

View file

@ -18,6 +18,7 @@ use std::pin::Pin;
///
/// Content inserts or replaces the contents of a record entirely
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Content<'r, C: Connection, D, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) method: Method,

View file

@ -14,6 +14,7 @@ use std::pin::Pin;
/// A record create future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Create<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) resource: Result<Resource>,

View file

@ -14,6 +14,7 @@ use std::pin::Pin;
/// A record delete future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Delete<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) resource: Result<Resource>,

View file

@ -12,6 +12,7 @@ use std::pin::Pin;
/// A database export future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Export<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) file: PathBuf,

View file

@ -9,6 +9,7 @@ use std::pin::Pin;
/// A health check future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Health<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
}

View file

@ -12,6 +12,7 @@ use std::pin::Pin;
/// An database import future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Import<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) file: PathBuf,

View file

@ -11,6 +11,7 @@ use std::pin::Pin;
/// A session invalidate future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Invalidate<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
}

View file

@ -10,6 +10,7 @@ use std::pin::Pin;
/// A live query kill future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Kill<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) query_id: Uuid,

View file

@ -12,6 +12,7 @@ use std::pin::Pin;
/// A live query future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Live<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) table_name: String,

View file

@ -16,6 +16,7 @@ use std::pin::Pin;
/// A merge future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Merge<'r, C: Connection, D, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) resource: Result<Resource>,

View file

@ -18,6 +18,7 @@ use std::result::Result as StdResult;
/// A patch future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Patch<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) resource: Result<Resource>,

View file

@ -25,6 +25,7 @@ use std::pin::Pin;
/// A query future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Query<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) query: Vec<Result<Vec<Statement>>>,

View file

@ -14,6 +14,7 @@ use std::pin::Pin;
/// A select future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Select<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) resource: Result<Resource>,

View file

@ -10,6 +10,7 @@ use std::pin::Pin;
/// A set future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Set<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) key: String,

View file

@ -14,6 +14,7 @@ use std::pin::Pin;
/// A signin future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Signin<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) credentials: Result<Value>,

View file

@ -14,6 +14,7 @@ use std::pin::Pin;
/// A signup future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Signup<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) credentials: Result<Value>,

View file

@ -9,6 +9,7 @@ use std::pin::Pin;
/// An unset future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Unset<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) key: String,

View file

@ -19,6 +19,7 @@ use std::pin::Pin;
/// An update future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Update<'r, C: Connection, R> {
pub(super) router: Result<&'r Router<C>>,
pub(super) resource: Result<Resource>,

View file

@ -9,6 +9,7 @@ use std::future::IntoFuture;
use crate::sql::Value;
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct UseDb<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) db: String,

View file

@ -9,6 +9,7 @@ use std::pin::Pin;
/// Stores the namespace to use
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct UseNs<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) ns: String,
@ -16,6 +17,7 @@ pub struct UseNs<'r, C: Connection> {
/// A use NS and DB future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct UseNsDb<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
pub(super) ns: String,

View file

@ -10,6 +10,7 @@ use std::pin::Pin;
/// A version future
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Version<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>,
}

View file

@ -38,6 +38,7 @@ pub trait Connection: conn::Connection {}
/// The future returned when creating a new SurrealDB instance
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Connect<'r, C: Connection, Response> {
router: Option<&'r OnceCell<Arc<Router<C>>>>,
address: Result<Endpoint>,
@ -76,7 +77,6 @@ where
/// # Ok(())
/// # }
/// ```
#[must_use]
pub const fn with_capacity(mut self, capacity: usize) -> Self {
self.capacity = capacity;
self

View file

@ -59,6 +59,7 @@ enum InnerOp<'a, T> {
///
/// [JSON Patch]: https://jsonpatch.com/
#[derive(Debug)]
#[must_use]
pub struct PatchOp(pub(crate) Result<Value, crate::err::Error>);
impl PatchOp {
@ -75,7 +76,6 @@ impl PatchOp {
/// PatchOp::add("/biscuits/1", json!({ "name": "Ginger Nut" }))
/// # ;
/// ```
#[must_use]
pub fn add<T>(path: &str, value: T) -> Self
where
T: Serialize,
@ -104,7 +104,6 @@ impl PatchOp {
/// PatchOp::remove("/biscuits/0")
/// # ;
/// ```
#[must_use]
pub fn remove(path: &str) -> Self {
Self(to_value(UnitOp::Remove {
path,
@ -122,7 +121,6 @@ impl PatchOp {
/// PatchOp::replace("/biscuits/0/name", "Chocolate Digestive")
/// # ;
/// ```
#[must_use]
pub fn replace<T>(path: &str, value: T) -> Self
where
T: Serialize,
@ -134,7 +132,6 @@ impl PatchOp {
}
/// Changes a value
#[must_use]
pub fn change(path: &str, diff: Diff) -> Self {
Self(to_value(UnitOp::Change {
path,