From 406ac6a7fc96a77f9430345b46ebabddb212e723 Mon Sep 17 00:00:00 2001 From: gwenn Date: Wed, 5 Jan 2022 19:40:31 +0100 Subject: [PATCH] clippy::must_use_candidate --- libsqlite3-sys/src/error.rs | 2 ++ libsqlite3-sys/src/lib.rs | 2 ++ src/backup.rs | 1 + src/blob/mod.rs | 3 +++ src/column.rs | 2 ++ src/functions.rs | 3 +++ src/row.rs | 1 + src/transaction.rs | 2 ++ src/types/value.rs | 1 + src/types/value_ref.rs | 1 + src/version.rs | 2 ++ src/vtab/mod.rs | 16 ++++++++++++++++ 12 files changed, 36 insertions(+) diff --git a/libsqlite3-sys/src/error.rs b/libsqlite3-sys/src/error.rs index 5e31ab5..16754ed 100644 --- a/libsqlite3-sys/src/error.rs +++ b/libsqlite3-sys/src/error.rs @@ -63,6 +63,7 @@ pub struct Error { } impl Error { + #[must_use] pub fn new(result_code: c_int) -> Error { let code = match result_code & 0xff { super::SQLITE_INTERNAL => ErrorCode::InternalMalfunction, @@ -192,6 +193,7 @@ const SQLITE_WARNING_AUTOINDEX: c_int = SQLITE_WARNING | (1 << 8); const SQLITE_AUTH_USER: c_int = super::SQLITE_AUTH | (1 << 8); +#[must_use] pub fn code_to_str(code: c_int) -> &'static str { match code { super::SQLITE_OK => "Successful result", diff --git a/libsqlite3-sys/src/lib.rs b/libsqlite3-sys/src/lib.rs index 5757194..9dae8e8 100644 --- a/libsqlite3-sys/src/lib.rs +++ b/libsqlite3-sys/src/lib.rs @@ -12,10 +12,12 @@ use std::mem; mod error; +#[must_use] pub fn SQLITE_STATIC() -> sqlite3_destructor_type { None } +#[must_use] pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type { Some(unsafe { mem::transmute(-1isize) }) } diff --git a/src/backup.rs b/src/backup.rs index 5104f73..b9e7a50 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -231,6 +231,7 @@ impl Backup<'_, '_> { /// Gets the progress of the backup as of the last call to /// [`step`](Backup::step). #[inline] + #[must_use] pub fn progress(&self) -> Progress { unsafe { Progress { diff --git a/src/blob/mod.rs b/src/blob/mod.rs index 2b13e1d..f221d61 100644 --- a/src/blob/mod.rs +++ b/src/blob/mod.rs @@ -265,12 +265,14 @@ impl Blob<'_> { /// Return the size in bytes of the BLOB. #[inline] + #[must_use] pub fn size(&self) -> i32 { unsafe { ffi::sqlite3_blob_bytes(self.blob) } } /// Return the current size in bytes of the BLOB. #[inline] + #[must_use] pub fn len(&self) -> usize { use std::convert::TryInto; self.size().try_into().unwrap() @@ -278,6 +280,7 @@ impl Blob<'_> { /// Return true if the BLOB is empty. #[inline] + #[must_use] pub fn is_empty(&self) -> bool { self.size() == 0 } diff --git a/src/column.rs b/src/column.rs index 94663e6..aa1f5f7 100644 --- a/src/column.rs +++ b/src/column.rs @@ -12,12 +12,14 @@ pub struct Column<'stmt> { impl Column<'_> { /// Returns the name of the column. #[inline] + #[must_use] pub fn name(&self) -> &str { self.name } /// Returns the type of the column (`None` for expression). #[inline] + #[must_use] pub fn decl_type(&self) -> Option<&str> { self.decl_type } diff --git a/src/functions.rs b/src/functions.rs index c19d843..e9463c2 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -114,12 +114,14 @@ pub struct Context<'a> { impl Context<'_> { /// Returns the number of arguments to the function. #[inline] + #[must_use] pub fn len(&self) -> usize { self.args.len() } /// Returns `true` when there is no argument. #[inline] + #[must_use] pub fn is_empty(&self) -> bool { self.args.is_empty() } @@ -157,6 +159,7 @@ impl Context<'_> { /// Will panic if `idx` is greater than or equal to /// [`self.len()`](Context::len). #[inline] + #[must_use] pub fn get_raw(&self, idx: usize) -> ValueRef<'_> { let arg = self.args[idx]; unsafe { ValueRef::from_value(arg) } diff --git a/src/row.rs b/src/row.rs index 52636bd..e810251 100644 --- a/src/row.rs +++ b/src/row.rs @@ -80,6 +80,7 @@ impl<'stmt> Rows<'stmt> { } /// Give access to the underlying statement + #[must_use] pub fn as_ref(&self) -> Option<&Statement<'stmt>> { self.stmt } diff --git a/src/transaction.rs b/src/transaction.rs index 86dea1f..dabd929 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -169,6 +169,7 @@ impl Transaction<'_> { /// Get the current setting for what happens to the transaction when it is /// dropped. #[inline] + #[must_use] pub fn drop_behavior(&self) -> DropBehavior { self.drop_behavior } @@ -296,6 +297,7 @@ impl Savepoint<'_> { /// Get the current setting for what happens to the savepoint when it is /// dropped. #[inline] + #[must_use] pub fn drop_behavior(&self) -> DropBehavior { self.drop_behavior } diff --git a/src/types/value.rs b/src/types/value.rs index 04c2def..28a5637 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -129,6 +129,7 @@ where impl Value { /// Returns SQLite fundamental datatype. #[inline] + #[must_use] pub fn data_type(&self) -> Type { match *self { Value::Null => Type::Null, diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index a7cd416..f25335c 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -22,6 +22,7 @@ pub enum ValueRef<'a> { impl ValueRef<'_> { /// Returns SQLite fundamental datatype. #[inline] + #[must_use] pub fn data_type(&self) -> Type { match *self { ValueRef::Null => Type::Null, diff --git a/src/version.rs b/src/version.rs index 6f56ee2..d70af7e 100644 --- a/src/version.rs +++ b/src/version.rs @@ -6,6 +6,7 @@ use std::ffi::CStr; /// /// See [`sqlite3_libversion_number()`](https://www.sqlite.org/c3ref/libversion.html). #[inline] +#[must_use] pub fn version_number() -> i32 { unsafe { ffi::sqlite3_libversion_number() } } @@ -14,6 +15,7 @@ pub fn version_number() -> i32 { /// /// See [`sqlite3_libversion()`](https://www.sqlite.org/c3ref/libversion.html). #[inline] +#[must_use] pub fn version() -> &'static str { let cstr = unsafe { CStr::from_ptr(ffi::sqlite3_libversion()) }; cstr.to_str() diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index 0d91d9f..84da8b7 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -87,6 +87,7 @@ const ZERO_MODULE: ffi::sqlite3_module = unsafe { /// Create a read-only virtual table implementation. /// /// Step 2 of [Creating New Virtual Table Implementations](https://sqlite.org/vtab.html#creating_new_virtual_table_implementations). +#[must_use] pub fn read_only_module<'vtab, T: CreateVTab<'vtab>>() -> &'static Module<'vtab, T> { // The xConnect and xCreate methods do the same thing, but they must be // different so that the virtual table is not an eponymous virtual table. @@ -126,6 +127,7 @@ pub fn read_only_module<'vtab, T: CreateVTab<'vtab>>() -> &'static Module<'vtab, /// Create an eponymous only virtual table implementation. /// /// Step 2 of [Creating New Virtual Table Implementations](https://sqlite.org/vtab.html#creating_new_virtual_table_implementations). +#[must_use] pub fn eponymous_only_module<'vtab, T: VTab<'vtab>>() -> &'static Module<'vtab, T> { // A virtual table is eponymous if its xCreate method is the exact same function // as the xConnect method For eponymous-only virtual tables, the xCreate @@ -326,6 +328,7 @@ impl IndexInfo { /// Record WHERE clause constraints. #[inline] + #[must_use] pub fn constraints(&self) -> IndexConstraintIter<'_> { let constraints = unsafe { slice::from_raw_parts((*self.0).aConstraint, (*self.0).nConstraint as usize) }; @@ -336,6 +339,7 @@ impl IndexInfo { /// Information about the ORDER BY clause. #[inline] + #[must_use] pub fn order_bys(&self) -> OrderByIter<'_> { let order_bys = unsafe { slice::from_raw_parts((*self.0).aOrderBy, (*self.0).nOrderBy as usize) }; @@ -346,6 +350,7 @@ impl IndexInfo { /// Number of terms in the ORDER BY clause #[inline] + #[must_use] pub fn num_of_order_by(&self) -> usize { unsafe { (*self.0).nOrderBy as usize } } @@ -448,18 +453,21 @@ pub struct IndexConstraint<'a>(&'a ffi::sqlite3_index_constraint); impl IndexConstraint<'_> { /// Column constrained. -1 for ROWID #[inline] + #[must_use] pub fn column(&self) -> c_int { self.0.iColumn } /// Constraint operator #[inline] + #[must_use] pub fn operator(&self) -> IndexConstraintOp { IndexConstraintOp::from(self.0.op) } /// True if this constraint is usable #[inline] + #[must_use] pub fn is_usable(&self) -> bool { self.0.usable != 0 } @@ -509,12 +517,14 @@ pub struct OrderBy<'a>(&'a ffi::sqlite3_index_info_sqlite3_index_orderby); impl OrderBy<'_> { /// Column number #[inline] + #[must_use] pub fn column(&self) -> c_int { self.0.iColumn } /// True for DESC. False for ASC. #[inline] + #[must_use] pub fn is_order_by_desc(&self) -> bool { self.0.desc != 0 } @@ -581,12 +591,14 @@ pub struct Values<'a> { impl Values<'_> { /// Returns the number of values. #[inline] + #[must_use] pub fn len(&self) -> usize { self.args.len() } /// Returns `true` if there is no value. #[inline] + #[must_use] pub fn is_empty(&self) -> bool { self.args.is_empty() } @@ -629,6 +641,7 @@ impl Values<'_> { /// Turns `Values` into an iterator. #[inline] + #[must_use] pub fn iter(&self) -> ValueIter<'_> { ValueIter { iter: self.args.iter(), @@ -720,6 +733,7 @@ impl InnerConnection { /// Escape double-quote (`"`) character occurrences by /// doubling them (`""`). +#[must_use] pub fn escape_double_quote(identifier: &str) -> Cow<'_, str> { if identifier.contains('"') { // escape quote by doubling them @@ -729,6 +743,7 @@ pub fn escape_double_quote(identifier: &str) -> Cow<'_, str> { } } /// Dequote string +#[must_use] pub fn dequote(s: &str) -> &str { if s.len() < 2 { return s; @@ -746,6 +761,7 @@ pub fn dequote(s: &str) -> &str { /// 1 yes true on /// 0 no false off /// ``` +#[must_use] pub fn parse_boolean(s: &str) -> Option { if s.eq_ignore_ascii_case("yes") || s.eq_ignore_ascii_case("on")