From 32352f4bd15b289eee5d3357f0222fea85b468ed Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Wed, 19 Apr 2023 10:26:22 +0200 Subject: [PATCH] Add more `#[must_use]` attributes (#1828) --- lib/src/api/method/authenticate.rs | 1 + lib/src/api/method/begin.rs | 2 ++ lib/src/api/method/cancel.rs | 1 + lib/src/api/method/commit.rs | 1 + lib/src/api/method/content.rs | 1 + lib/src/api/method/create.rs | 1 + lib/src/api/method/delete.rs | 1 + lib/src/api/method/export.rs | 1 + lib/src/api/method/health.rs | 1 + lib/src/api/method/import.rs | 1 + lib/src/api/method/invalidate.rs | 1 + lib/src/api/method/kill.rs | 1 + lib/src/api/method/live.rs | 1 + lib/src/api/method/merge.rs | 1 + lib/src/api/method/patch.rs | 1 + lib/src/api/method/query.rs | 1 + lib/src/api/method/select.rs | 1 + lib/src/api/method/set.rs | 1 + lib/src/api/method/signin.rs | 1 + lib/src/api/method/signup.rs | 1 + lib/src/api/method/unset.rs | 1 + lib/src/api/method/update.rs | 1 + lib/src/api/method/use_db.rs | 1 + lib/src/api/method/use_ns.rs | 2 ++ lib/src/api/method/version.rs | 1 + lib/src/api/mod.rs | 2 +- lib/src/api/opt/mod.rs | 5 +---- 27 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/src/api/method/authenticate.rs b/lib/src/api/method/authenticate.rs index 41ccf032..9d64d647 100644 --- a/lib/src/api/method/authenticate.rs +++ b/lib/src/api/method/authenticate.rs @@ -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>, pub(super) token: Jwt, diff --git a/lib/src/api/method/begin.rs b/lib/src/api/method/begin.rs index e254a259..02ea7723 100644 --- a/lib/src/api/method/begin.rs +++ b/lib/src/api/method/begin.rs @@ -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 { pub(super) client: Surreal, } @@ -34,6 +35,7 @@ where /// An ongoing transaction #[derive(Debug)] +#[must_use = "transactions must be committed or cancelled to complete them"] pub struct Transaction { client: Surreal, } diff --git a/lib/src/api/method/cancel.rs b/lib/src/api/method/cancel.rs index 15179c2c..1d46cee1 100644 --- a/lib/src/api/method/cancel.rs +++ b/lib/src/api/method/cancel.rs @@ -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 { pub(crate) client: Surreal, } diff --git a/lib/src/api/method/commit.rs b/lib/src/api/method/commit.rs index 3eb876b5..d4df64c2 100644 --- a/lib/src/api/method/commit.rs +++ b/lib/src/api/method/commit.rs @@ -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 { pub(crate) client: Surreal, } diff --git a/lib/src/api/method/content.rs b/lib/src/api/method/content.rs index 5b444618..8b90d110 100644 --- a/lib/src/api/method/content.rs +++ b/lib/src/api/method/content.rs @@ -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>, pub(super) method: Method, diff --git a/lib/src/api/method/create.rs b/lib/src/api/method/create.rs index 250ca5ea..7899c7b4 100644 --- a/lib/src/api/method/create.rs +++ b/lib/src/api/method/create.rs @@ -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>, pub(super) resource: Result, diff --git a/lib/src/api/method/delete.rs b/lib/src/api/method/delete.rs index 4e190292..feddd9d0 100644 --- a/lib/src/api/method/delete.rs +++ b/lib/src/api/method/delete.rs @@ -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>, pub(super) resource: Result, diff --git a/lib/src/api/method/export.rs b/lib/src/api/method/export.rs index 359c4286..0a8778dd 100644 --- a/lib/src/api/method/export.rs +++ b/lib/src/api/method/export.rs @@ -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>, pub(super) file: PathBuf, diff --git a/lib/src/api/method/health.rs b/lib/src/api/method/health.rs index 2bed4023..a498173a 100644 --- a/lib/src/api/method/health.rs +++ b/lib/src/api/method/health.rs @@ -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>, } diff --git a/lib/src/api/method/import.rs b/lib/src/api/method/import.rs index eec5bab5..d9bf9cde 100644 --- a/lib/src/api/method/import.rs +++ b/lib/src/api/method/import.rs @@ -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>, pub(super) file: PathBuf, diff --git a/lib/src/api/method/invalidate.rs b/lib/src/api/method/invalidate.rs index a31b7348..692080ed 100644 --- a/lib/src/api/method/invalidate.rs +++ b/lib/src/api/method/invalidate.rs @@ -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>, } diff --git a/lib/src/api/method/kill.rs b/lib/src/api/method/kill.rs index 8346de99..35be47aa 100644 --- a/lib/src/api/method/kill.rs +++ b/lib/src/api/method/kill.rs @@ -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>, pub(super) query_id: Uuid, diff --git a/lib/src/api/method/live.rs b/lib/src/api/method/live.rs index 99f9e9a3..caf59742 100644 --- a/lib/src/api/method/live.rs +++ b/lib/src/api/method/live.rs @@ -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>, pub(super) table_name: String, diff --git a/lib/src/api/method/merge.rs b/lib/src/api/method/merge.rs index a18952bd..e857a7d5 100644 --- a/lib/src/api/method/merge.rs +++ b/lib/src/api/method/merge.rs @@ -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>, pub(super) resource: Result, diff --git a/lib/src/api/method/patch.rs b/lib/src/api/method/patch.rs index 1d410b0d..1a7c8b4e 100644 --- a/lib/src/api/method/patch.rs +++ b/lib/src/api/method/patch.rs @@ -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>, pub(super) resource: Result, diff --git a/lib/src/api/method/query.rs b/lib/src/api/method/query.rs index f4479f75..ffc6c0a6 100644 --- a/lib/src/api/method/query.rs +++ b/lib/src/api/method/query.rs @@ -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>, pub(super) query: Vec>>, diff --git a/lib/src/api/method/select.rs b/lib/src/api/method/select.rs index 6ba07016..656eb5d0 100644 --- a/lib/src/api/method/select.rs +++ b/lib/src/api/method/select.rs @@ -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>, pub(super) resource: Result, diff --git a/lib/src/api/method/set.rs b/lib/src/api/method/set.rs index 9b4d60f8..fab0b061 100644 --- a/lib/src/api/method/set.rs +++ b/lib/src/api/method/set.rs @@ -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>, pub(super) key: String, diff --git a/lib/src/api/method/signin.rs b/lib/src/api/method/signin.rs index f2b1975b..b99af53d 100644 --- a/lib/src/api/method/signin.rs +++ b/lib/src/api/method/signin.rs @@ -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>, pub(super) credentials: Result, diff --git a/lib/src/api/method/signup.rs b/lib/src/api/method/signup.rs index 18565217..c6156871 100644 --- a/lib/src/api/method/signup.rs +++ b/lib/src/api/method/signup.rs @@ -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>, pub(super) credentials: Result, diff --git a/lib/src/api/method/unset.rs b/lib/src/api/method/unset.rs index b088ab59..c780d8eb 100644 --- a/lib/src/api/method/unset.rs +++ b/lib/src/api/method/unset.rs @@ -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>, pub(super) key: String, diff --git a/lib/src/api/method/update.rs b/lib/src/api/method/update.rs index fcb82434..3e60741f 100644 --- a/lib/src/api/method/update.rs +++ b/lib/src/api/method/update.rs @@ -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>, pub(super) resource: Result, diff --git a/lib/src/api/method/use_db.rs b/lib/src/api/method/use_db.rs index f0704513..2ddf8c10 100644 --- a/lib/src/api/method/use_db.rs +++ b/lib/src/api/method/use_db.rs @@ -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>, pub(super) db: String, diff --git a/lib/src/api/method/use_ns.rs b/lib/src/api/method/use_ns.rs index 246958a9..df4858e2 100644 --- a/lib/src/api/method/use_ns.rs +++ b/lib/src/api/method/use_ns.rs @@ -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>, 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>, pub(super) ns: String, diff --git a/lib/src/api/method/version.rs b/lib/src/api/method/version.rs index 7791d53f..ef6a705d 100644 --- a/lib/src/api/method/version.rs +++ b/lib/src/api/method/version.rs @@ -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>, } diff --git a/lib/src/api/mod.rs b/lib/src/api/mod.rs index 02c91702..07d2480c 100644 --- a/lib/src/api/mod.rs +++ b/lib/src/api/mod.rs @@ -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>>>, address: Result, @@ -76,7 +77,6 @@ where /// # Ok(()) /// # } /// ``` - #[must_use] pub const fn with_capacity(mut self, capacity: usize) -> Self { self.capacity = capacity; self diff --git a/lib/src/api/opt/mod.rs b/lib/src/api/opt/mod.rs index 49f5e83c..207e8e57 100644 --- a/lib/src/api/opt/mod.rs +++ b/lib/src/api/opt/mod.rs @@ -59,6 +59,7 @@ enum InnerOp<'a, T> { /// /// [JSON Patch]: https://jsonpatch.com/ #[derive(Debug)] +#[must_use] pub struct PatchOp(pub(crate) Result); impl PatchOp { @@ -75,7 +76,6 @@ impl PatchOp { /// PatchOp::add("/biscuits/1", json!({ "name": "Ginger Nut" })) /// # ; /// ``` - #[must_use] pub fn add(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(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,