clippy::must_use_candidate

This commit is contained in:
gwenn 2022-01-05 19:40:31 +01:00 committed by Thom Chiovoloni
parent bcfe99578b
commit 406ac6a7fc
12 changed files with 36 additions and 0 deletions

View File

@ -63,6 +63,7 @@ pub struct Error {
} }
impl Error { impl Error {
#[must_use]
pub fn new(result_code: c_int) -> Error { pub fn new(result_code: c_int) -> Error {
let code = match result_code & 0xff { let code = match result_code & 0xff {
super::SQLITE_INTERNAL => ErrorCode::InternalMalfunction, 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); const SQLITE_AUTH_USER: c_int = super::SQLITE_AUTH | (1 << 8);
#[must_use]
pub fn code_to_str(code: c_int) -> &'static str { pub fn code_to_str(code: c_int) -> &'static str {
match code { match code {
super::SQLITE_OK => "Successful result", super::SQLITE_OK => "Successful result",

View File

@ -12,10 +12,12 @@ use std::mem;
mod error; mod error;
#[must_use]
pub fn SQLITE_STATIC() -> sqlite3_destructor_type { pub fn SQLITE_STATIC() -> sqlite3_destructor_type {
None None
} }
#[must_use]
pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type { pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type {
Some(unsafe { mem::transmute(-1isize) }) Some(unsafe { mem::transmute(-1isize) })
} }

View File

@ -231,6 +231,7 @@ impl Backup<'_, '_> {
/// Gets the progress of the backup as of the last call to /// Gets the progress of the backup as of the last call to
/// [`step`](Backup::step). /// [`step`](Backup::step).
#[inline] #[inline]
#[must_use]
pub fn progress(&self) -> Progress { pub fn progress(&self) -> Progress {
unsafe { unsafe {
Progress { Progress {

View File

@ -265,12 +265,14 @@ impl Blob<'_> {
/// Return the size in bytes of the BLOB. /// Return the size in bytes of the BLOB.
#[inline] #[inline]
#[must_use]
pub fn size(&self) -> i32 { pub fn size(&self) -> i32 {
unsafe { ffi::sqlite3_blob_bytes(self.blob) } unsafe { ffi::sqlite3_blob_bytes(self.blob) }
} }
/// Return the current size in bytes of the BLOB. /// Return the current size in bytes of the BLOB.
#[inline] #[inline]
#[must_use]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
use std::convert::TryInto; use std::convert::TryInto;
self.size().try_into().unwrap() self.size().try_into().unwrap()
@ -278,6 +280,7 @@ impl Blob<'_> {
/// Return true if the BLOB is empty. /// Return true if the BLOB is empty.
#[inline] #[inline]
#[must_use]
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.size() == 0 self.size() == 0
} }

View File

@ -12,12 +12,14 @@ pub struct Column<'stmt> {
impl Column<'_> { impl Column<'_> {
/// Returns the name of the column. /// Returns the name of the column.
#[inline] #[inline]
#[must_use]
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
self.name self.name
} }
/// Returns the type of the column (`None` for expression). /// Returns the type of the column (`None` for expression).
#[inline] #[inline]
#[must_use]
pub fn decl_type(&self) -> Option<&str> { pub fn decl_type(&self) -> Option<&str> {
self.decl_type self.decl_type
} }

View File

@ -114,12 +114,14 @@ pub struct Context<'a> {
impl Context<'_> { impl Context<'_> {
/// Returns the number of arguments to the function. /// Returns the number of arguments to the function.
#[inline] #[inline]
#[must_use]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.args.len() self.args.len()
} }
/// Returns `true` when there is no argument. /// Returns `true` when there is no argument.
#[inline] #[inline]
#[must_use]
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.args.is_empty() self.args.is_empty()
} }
@ -157,6 +159,7 @@ impl Context<'_> {
/// Will panic if `idx` is greater than or equal to /// Will panic if `idx` is greater than or equal to
/// [`self.len()`](Context::len). /// [`self.len()`](Context::len).
#[inline] #[inline]
#[must_use]
pub fn get_raw(&self, idx: usize) -> ValueRef<'_> { pub fn get_raw(&self, idx: usize) -> ValueRef<'_> {
let arg = self.args[idx]; let arg = self.args[idx];
unsafe { ValueRef::from_value(arg) } unsafe { ValueRef::from_value(arg) }

View File

@ -80,6 +80,7 @@ impl<'stmt> Rows<'stmt> {
} }
/// Give access to the underlying statement /// Give access to the underlying statement
#[must_use]
pub fn as_ref(&self) -> Option<&Statement<'stmt>> { pub fn as_ref(&self) -> Option<&Statement<'stmt>> {
self.stmt self.stmt
} }

View File

@ -169,6 +169,7 @@ impl Transaction<'_> {
/// Get the current setting for what happens to the transaction when it is /// Get the current setting for what happens to the transaction when it is
/// dropped. /// dropped.
#[inline] #[inline]
#[must_use]
pub fn drop_behavior(&self) -> DropBehavior { pub fn drop_behavior(&self) -> DropBehavior {
self.drop_behavior self.drop_behavior
} }
@ -296,6 +297,7 @@ impl Savepoint<'_> {
/// Get the current setting for what happens to the savepoint when it is /// Get the current setting for what happens to the savepoint when it is
/// dropped. /// dropped.
#[inline] #[inline]
#[must_use]
pub fn drop_behavior(&self) -> DropBehavior { pub fn drop_behavior(&self) -> DropBehavior {
self.drop_behavior self.drop_behavior
} }

View File

@ -129,6 +129,7 @@ where
impl Value { impl Value {
/// Returns SQLite fundamental datatype. /// Returns SQLite fundamental datatype.
#[inline] #[inline]
#[must_use]
pub fn data_type(&self) -> Type { pub fn data_type(&self) -> Type {
match *self { match *self {
Value::Null => Type::Null, Value::Null => Type::Null,

View File

@ -22,6 +22,7 @@ pub enum ValueRef<'a> {
impl ValueRef<'_> { impl ValueRef<'_> {
/// Returns SQLite fundamental datatype. /// Returns SQLite fundamental datatype.
#[inline] #[inline]
#[must_use]
pub fn data_type(&self) -> Type { pub fn data_type(&self) -> Type {
match *self { match *self {
ValueRef::Null => Type::Null, ValueRef::Null => Type::Null,

View File

@ -6,6 +6,7 @@ use std::ffi::CStr;
/// ///
/// See [`sqlite3_libversion_number()`](https://www.sqlite.org/c3ref/libversion.html). /// See [`sqlite3_libversion_number()`](https://www.sqlite.org/c3ref/libversion.html).
#[inline] #[inline]
#[must_use]
pub fn version_number() -> i32 { pub fn version_number() -> i32 {
unsafe { ffi::sqlite3_libversion_number() } unsafe { ffi::sqlite3_libversion_number() }
} }
@ -14,6 +15,7 @@ pub fn version_number() -> i32 {
/// ///
/// See [`sqlite3_libversion()`](https://www.sqlite.org/c3ref/libversion.html). /// See [`sqlite3_libversion()`](https://www.sqlite.org/c3ref/libversion.html).
#[inline] #[inline]
#[must_use]
pub fn version() -> &'static str { pub fn version() -> &'static str {
let cstr = unsafe { CStr::from_ptr(ffi::sqlite3_libversion()) }; let cstr = unsafe { CStr::from_ptr(ffi::sqlite3_libversion()) };
cstr.to_str() cstr.to_str()

View File

@ -87,6 +87,7 @@ const ZERO_MODULE: ffi::sqlite3_module = unsafe {
/// Create a read-only virtual table implementation. /// 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). /// 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> { 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 // 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. // 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. /// 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). /// 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> { 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 // 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 // as the xConnect method For eponymous-only virtual tables, the xCreate
@ -326,6 +328,7 @@ impl IndexInfo {
/// Record WHERE clause constraints. /// Record WHERE clause constraints.
#[inline] #[inline]
#[must_use]
pub fn constraints(&self) -> IndexConstraintIter<'_> { pub fn constraints(&self) -> IndexConstraintIter<'_> {
let constraints = let constraints =
unsafe { slice::from_raw_parts((*self.0).aConstraint, (*self.0).nConstraint as usize) }; 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. /// Information about the ORDER BY clause.
#[inline] #[inline]
#[must_use]
pub fn order_bys(&self) -> OrderByIter<'_> { pub fn order_bys(&self) -> OrderByIter<'_> {
let order_bys = let order_bys =
unsafe { slice::from_raw_parts((*self.0).aOrderBy, (*self.0).nOrderBy as usize) }; 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 /// Number of terms in the ORDER BY clause
#[inline] #[inline]
#[must_use]
pub fn num_of_order_by(&self) -> usize { pub fn num_of_order_by(&self) -> usize {
unsafe { (*self.0).nOrderBy as usize } unsafe { (*self.0).nOrderBy as usize }
} }
@ -448,18 +453,21 @@ pub struct IndexConstraint<'a>(&'a ffi::sqlite3_index_constraint);
impl IndexConstraint<'_> { impl IndexConstraint<'_> {
/// Column constrained. -1 for ROWID /// Column constrained. -1 for ROWID
#[inline] #[inline]
#[must_use]
pub fn column(&self) -> c_int { pub fn column(&self) -> c_int {
self.0.iColumn self.0.iColumn
} }
/// Constraint operator /// Constraint operator
#[inline] #[inline]
#[must_use]
pub fn operator(&self) -> IndexConstraintOp { pub fn operator(&self) -> IndexConstraintOp {
IndexConstraintOp::from(self.0.op) IndexConstraintOp::from(self.0.op)
} }
/// True if this constraint is usable /// True if this constraint is usable
#[inline] #[inline]
#[must_use]
pub fn is_usable(&self) -> bool { pub fn is_usable(&self) -> bool {
self.0.usable != 0 self.0.usable != 0
} }
@ -509,12 +517,14 @@ pub struct OrderBy<'a>(&'a ffi::sqlite3_index_info_sqlite3_index_orderby);
impl OrderBy<'_> { impl OrderBy<'_> {
/// Column number /// Column number
#[inline] #[inline]
#[must_use]
pub fn column(&self) -> c_int { pub fn column(&self) -> c_int {
self.0.iColumn self.0.iColumn
} }
/// True for DESC. False for ASC. /// True for DESC. False for ASC.
#[inline] #[inline]
#[must_use]
pub fn is_order_by_desc(&self) -> bool { pub fn is_order_by_desc(&self) -> bool {
self.0.desc != 0 self.0.desc != 0
} }
@ -581,12 +591,14 @@ pub struct Values<'a> {
impl Values<'_> { impl Values<'_> {
/// Returns the number of values. /// Returns the number of values.
#[inline] #[inline]
#[must_use]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.args.len() self.args.len()
} }
/// Returns `true` if there is no value. /// Returns `true` if there is no value.
#[inline] #[inline]
#[must_use]
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.args.is_empty() self.args.is_empty()
} }
@ -629,6 +641,7 @@ impl Values<'_> {
/// Turns `Values` into an iterator. /// Turns `Values` into an iterator.
#[inline] #[inline]
#[must_use]
pub fn iter(&self) -> ValueIter<'_> { pub fn iter(&self) -> ValueIter<'_> {
ValueIter { ValueIter {
iter: self.args.iter(), iter: self.args.iter(),
@ -720,6 +733,7 @@ impl InnerConnection {
/// Escape double-quote (`"`) character occurrences by /// Escape double-quote (`"`) character occurrences by
/// doubling them (`""`). /// doubling them (`""`).
#[must_use]
pub fn escape_double_quote(identifier: &str) -> Cow<'_, str> { pub fn escape_double_quote(identifier: &str) -> Cow<'_, str> {
if identifier.contains('"') { if identifier.contains('"') {
// escape quote by doubling them // escape quote by doubling them
@ -729,6 +743,7 @@ pub fn escape_double_quote(identifier: &str) -> Cow<'_, str> {
} }
} }
/// Dequote string /// Dequote string
#[must_use]
pub fn dequote(s: &str) -> &str { pub fn dequote(s: &str) -> &str {
if s.len() < 2 { if s.len() < 2 {
return s; return s;
@ -746,6 +761,7 @@ pub fn dequote(s: &str) -> &str {
/// 1 yes true on /// 1 yes true on
/// 0 no false off /// 0 no false off
/// ``` /// ```
#[must_use]
pub fn parse_boolean(s: &str) -> Option<bool> { pub fn parse_boolean(s: &str) -> Option<bool> {
if s.eq_ignore_ascii_case("yes") if s.eq_ignore_ascii_case("yes")
|| s.eq_ignore_ascii_case("on") || s.eq_ignore_ascii_case("on")