mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 13:58:55 +08:00 
			
		
		
		
	clippy::must_use_candidate
This commit is contained in:
		| @@ -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", | ||||
|   | ||||
| @@ -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) }) | ||||
| } | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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 | ||||
|     } | ||||
|   | ||||
| @@ -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 | ||||
|     } | ||||
|   | ||||
| @@ -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) } | ||||
|   | ||||
| @@ -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 | ||||
|     } | ||||
|   | ||||
| @@ -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 | ||||
|     } | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
| @@ -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<bool> { | ||||
|     if s.eq_ignore_ascii_case("yes") | ||||
|         || s.eq_ignore_ascii_case("on") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user