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 /// An authentication future
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Authenticate<'r, C: Connection> { pub struct Authenticate<'r, C: Connection> {
pub(super) router: Result<&'r Router<C>>, pub(super) router: Result<&'r Router<C>>,
pub(super) token: Jwt, pub(super) token: Jwt,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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