Skip to content

ran cargo clippy --fix -- -Wclippy::use_self #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/duckdb/src/arrow_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Arrow<'stmt> {
#[allow(clippy::needless_lifetimes)]
impl<'stmt> Arrow<'stmt> {
#[inline]
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Arrow<'stmt> {
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Self {
Arrow { stmt: Some(stmt) }
}

Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct ArrowStream<'stmt> {
#[allow(clippy::needless_lifetimes)]
impl<'stmt> ArrowStream<'stmt> {
#[inline]
pub(crate) fn new(stmt: &'stmt Statement<'stmt>, schema: SchemaRef) -> ArrowStream<'stmt> {
pub(crate) fn new(stmt: &'stmt Statement<'stmt>, schema: SchemaRef) -> Self {
ArrowStream {
stmt: Some(stmt),
schema,
Expand Down
4 changes: 2 additions & 2 deletions crates/duckdb/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl CachedStatement<'_> {
impl StatementCache {
/// Create a statement cache.
#[inline]
pub fn with_capacity(capacity: usize) -> StatementCache {
StatementCache(RefCell::new(LruCache::new(capacity)))
pub fn with_capacity(capacity: usize) -> Self {
Self(RefCell::new(LruCache::new(capacity)))
}

#[inline]
Expand Down
22 changes: 11 additions & 11 deletions crates/duckdb/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,69 +53,69 @@ impl Config {
}

/// enable autoload extensions
pub fn enable_autoload_extension(mut self, enabled: bool) -> Result<Config> {
pub fn enable_autoload_extension(mut self, enabled: bool) -> Result<Self> {
self.set("autoinstall_known_extensions", &(enabled as i32).to_string())?;
self.set("autoload_known_extensions", &(enabled as i32).to_string())?;
Ok(self)
}

/// Access mode of the database ([AUTOMATIC], READ_ONLY or READ_WRITE)
pub fn access_mode(mut self, mode: AccessMode) -> Result<Config> {
pub fn access_mode(mut self, mode: AccessMode) -> Result<Self> {
self.set("access_mode", &mode.to_string())?;
Ok(self)
}

/// Metadata from DuckDB callers
pub fn custom_user_agent(mut self, custom_user_agent: &str) -> Result<Config> {
pub fn custom_user_agent(mut self, custom_user_agent: &str) -> Result<Self> {
self.set("custom_user_agent", custom_user_agent)?;
Ok(self)
}

/// The order type used when none is specified ([ASC] or DESC)
pub fn default_order(mut self, order: DefaultOrder) -> Result<Config> {
pub fn default_order(mut self, order: DefaultOrder) -> Result<Self> {
self.set("default_order", &order.to_string())?;
Ok(self)
}

/// Null ordering used when none is specified ([NULLS_FIRST] or NULLS_LAST)
pub fn default_null_order(mut self, null_order: DefaultNullOrder) -> Result<Config> {
pub fn default_null_order(mut self, null_order: DefaultNullOrder) -> Result<Self> {
self.set("default_null_order", &null_order.to_string())?;
Ok(self)
}

/// Allow the database to access external state (through e.g. COPY TO/FROM, CSV readers, pandas replacement scans, etc)
pub fn enable_external_access(mut self, enabled: bool) -> Result<Config> {
pub fn enable_external_access(mut self, enabled: bool) -> Result<Self> {
self.set("enable_external_access", &enabled.to_string())?;
Ok(self)
}

/// Whether or not object cache is used to cache e.g. Parquet metadata
pub fn enable_object_cache(mut self, enabled: bool) -> Result<Config> {
pub fn enable_object_cache(mut self, enabled: bool) -> Result<Self> {
self.set("enable_object_cache", &enabled.to_string())?;
Ok(self)
}

/// Allow to load third-party duckdb extensions.
pub fn allow_unsigned_extensions(mut self) -> Result<Config> {
pub fn allow_unsigned_extensions(mut self) -> Result<Self> {
self.set("allow_unsigned_extensions", "true")?;
Ok(self)
}

/// The maximum memory of the system (e.g. 1GB)
pub fn max_memory(mut self, memory: &str) -> Result<Config> {
pub fn max_memory(mut self, memory: &str) -> Result<Self> {
self.set("max_memory", memory)?;
Ok(self)
}

/// The number of total threads used by the system
pub fn threads(mut self, thread_num: i64) -> Result<Config> {
pub fn threads(mut self, thread_num: i64) -> Result<Self> {
self.set("threads", &thread_num.to_string())?;
Ok(self)
}

/// Add any setting to the config. DuckDB will return an error if the setting is unknown or
/// otherwise invalid.
pub fn with(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Result<Config> {
pub fn with(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Result<Self> {
self.set(key.as_ref(), value.as_ref())?;
Ok(self)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/duckdb/src/core/data_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl DataChunkHandle {
let num_columns = logical_types.len();
let mut c_types = logical_types.iter().map(|t| t.ptr).collect::<Vec<_>>();
let ptr = unsafe { duckdb_create_data_chunk(c_types.as_mut_ptr(), num_columns as u64) };
DataChunkHandle { ptr, owned: true }
Self { ptr, owned: true }
}

/// Get the vector at the specific column index: `idx`.
Expand Down
10 changes: 5 additions & 5 deletions crates/duckdb/src/core/logical_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl LogicalTypeHandle {
}

/// Creates a map type from its child type.
pub fn map(key: &LogicalTypeHandle, value: &LogicalTypeHandle) -> Self {
pub fn map(key: &Self, value: &Self) -> Self {
unsafe {
Self {
ptr: duckdb_create_map_type(key.ptr, value.ptr),
Expand All @@ -174,7 +174,7 @@ impl LogicalTypeHandle {
}

/// Creates a list type from its child type.
pub fn list(child_type: &LogicalTypeHandle) -> Self {
pub fn list(child_type: &Self) -> Self {
unsafe {
Self {
ptr: duckdb_create_list_type(child_type.ptr),
Expand All @@ -183,7 +183,7 @@ impl LogicalTypeHandle {
}

/// Creates an array type from its child type.
pub fn array(child_type: &LogicalTypeHandle, array_size: u64) -> Self {
pub fn array(child_type: &Self, array_size: u64) -> Self {
unsafe {
Self {
ptr: duckdb_create_array_type(child_type.ptr, array_size),
Expand Down Expand Up @@ -213,7 +213,7 @@ impl LogicalTypeHandle {
}

/// Make a `LogicalType` for `struct`
pub fn struct_type(fields: &[(&str, LogicalTypeHandle)]) -> Self {
pub fn struct_type(fields: &[(&str, Self)]) -> Self {
let keys: Vec<CString> = fields.iter().map(|f| CString::new(f.0).unwrap()).collect();
let values: Vec<duckdb_logical_type> = fields.iter().map(|it| it.1.ptr).collect();
let name_ptrs = keys.iter().map(|it| it.as_ptr()).collect::<Vec<*const c_char>>();
Expand All @@ -230,7 +230,7 @@ impl LogicalTypeHandle {
}

/// Make a `LogicalType` for `union`
pub fn union_type(fields: &[(&str, LogicalTypeHandle)]) -> Self {
pub fn union_type(fields: &[(&str, Self)]) -> Self {
let keys: Vec<CString> = fields.iter().map(|f| CString::new(f.0).unwrap()).collect();
let values: Vec<duckdb_logical_type> = fields.iter().map(|it| it.1.ptr).collect();
let name_ptrs = keys.iter().map(|it| it.as_ptr()).collect::<Vec<*const c_char>>();
Expand Down
6 changes: 3 additions & 3 deletions crates/duckdb/src/core/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ impl ListVector {
}

/// Take the child as [ListVector].
pub fn list_child(&self) -> ListVector {
ListVector::from(unsafe { duckdb_list_vector_get_child(self.entries.ptr) })
pub fn list_child(&self) -> Self {
Self::from(unsafe { duckdb_list_vector_get_child(self.entries.ptr) })
}

/// Set primitive data to the child node.
Expand Down Expand Up @@ -309,7 +309,7 @@ impl StructVector {
}

/// Take the child as [StructVector].
pub fn struct_vector_child(&self, idx: usize) -> StructVector {
pub fn struct_vector_child(&self, idx: usize) -> Self {
Self::from(unsafe { duckdb_struct_vector_get_child(self.ptr, idx as u64) })
}

Expand Down
122 changes: 61 additions & 61 deletions crates/duckdb/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,39 @@ pub enum Error {
}

impl PartialEq for Error {
fn eq(&self, other: &Error) -> bool {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Error::DuckDBFailure(e1, s1), Error::DuckDBFailure(e2, s2)) => e1 == e2 && s1 == s2,
(Error::IntegralValueOutOfRange(i1, n1), Error::IntegralValueOutOfRange(i2, n2)) => i1 == i2 && n1 == n2,
(Error::Utf8Error(e1), Error::Utf8Error(e2)) => e1 == e2,
(Error::NulError(e1), Error::NulError(e2)) => e1 == e2,
(Error::InvalidParameterName(n1), Error::InvalidParameterName(n2)) => n1 == n2,
(Error::InvalidPath(p1), Error::InvalidPath(p2)) => p1 == p2,
(Error::ExecuteReturnedResults, Error::ExecuteReturnedResults) => true,
(Error::QueryReturnedNoRows, Error::QueryReturnedNoRows) => true,
(Error::InvalidColumnIndex(i1), Error::InvalidColumnIndex(i2)) => i1 == i2,
(Error::InvalidColumnName(n1), Error::InvalidColumnName(n2)) => n1 == n2,
(Error::InvalidColumnType(i1, n1, t1), Error::InvalidColumnType(i2, n2, t2)) => {
(Self::DuckDBFailure(e1, s1), Self::DuckDBFailure(e2, s2)) => e1 == e2 && s1 == s2,
(Self::IntegralValueOutOfRange(i1, n1), Self::IntegralValueOutOfRange(i2, n2)) => i1 == i2 && n1 == n2,
(Self::Utf8Error(e1), Self::Utf8Error(e2)) => e1 == e2,
(Self::NulError(e1), Self::NulError(e2)) => e1 == e2,
(Self::InvalidParameterName(n1), Self::InvalidParameterName(n2)) => n1 == n2,
(Self::InvalidPath(p1), Self::InvalidPath(p2)) => p1 == p2,
(Self::ExecuteReturnedResults, Self::ExecuteReturnedResults) => true,
(Self::QueryReturnedNoRows, Self::QueryReturnedNoRows) => true,
(Self::InvalidColumnIndex(i1), Self::InvalidColumnIndex(i2)) => i1 == i2,
(Self::InvalidColumnName(n1), Self::InvalidColumnName(n2)) => n1 == n2,
(Self::InvalidColumnType(i1, n1, t1), Self::InvalidColumnType(i2, n2, t2)) => {
i1 == i2 && t1 == t2 && n1 == n2
}
(Error::StatementChangedRows(n1), Error::StatementChangedRows(n2)) => n1 == n2,
(Error::InvalidParameterCount(i1, n1), Error::InvalidParameterCount(i2, n2)) => i1 == i2 && n1 == n2,
(Self::StatementChangedRows(n1), Self::StatementChangedRows(n2)) => n1 == n2,
(Self::InvalidParameterCount(i1, n1), Self::InvalidParameterCount(i2, n2)) => i1 == i2 && n1 == n2,
(..) => false,
}
}
}

impl From<str::Utf8Error> for Error {
#[cold]
fn from(err: str::Utf8Error) -> Error {
Error::Utf8Error(err)
fn from(err: str::Utf8Error) -> Self {
Self::Utf8Error(err)
}
}

impl From<::std::ffi::NulError> for Error {
#[cold]
fn from(err: ::std::ffi::NulError) -> Error {
Error::NulError(err)
fn from(err: ::std::ffi::NulError) -> Self {
Self::NulError(err)
}
}

Expand All @@ -128,90 +128,90 @@ const UNKNOWN_COLUMN: usize = usize::MAX;
/// to allow use of `get_raw(…).as_…()?` in callbacks that take `Error`.
impl From<FromSqlError> for Error {
#[cold]
fn from(err: FromSqlError) -> Error {
fn from(err: FromSqlError) -> Self {
// The error type requires index and type fields, but they aren't known in this
// context.
match err {
FromSqlError::OutOfRange(val) => Error::IntegralValueOutOfRange(UNKNOWN_COLUMN, val),
FromSqlError::OutOfRange(val) => Self::IntegralValueOutOfRange(UNKNOWN_COLUMN, val),
#[cfg(feature = "uuid")]
FromSqlError::InvalidUuidSize(_) => {
Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Blob, Box::new(err))
}
FromSqlError::Other(source) => Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, source),
_ => Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, Box::new(err)),
FromSqlError::Other(source) => Self::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, source),
_ => Self::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, Box::new(err)),
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Error::DuckDBFailure(ref err, None) => err.fmt(f),
Error::DuckDBFailure(_, Some(ref s)) => write!(f, "{s}"),
Error::FromSqlConversionFailure(i, ref t, ref err) => {
Self::DuckDBFailure(ref err, None) => err.fmt(f),
Self::DuckDBFailure(_, Some(ref s)) => write!(f, "{s}"),
Self::FromSqlConversionFailure(i, ref t, ref err) => {
if i != UNKNOWN_COLUMN {
write!(f, "Conversion error from type {t} at index: {i}, {err}")
} else {
err.fmt(f)
}
}
Error::IntegralValueOutOfRange(col, val) => {
Self::IntegralValueOutOfRange(col, val) => {
if col != UNKNOWN_COLUMN {
write!(f, "Integer {val} out of range at index {col}")
} else {
write!(f, "Integer {val} out of range")
}
}
Error::Utf8Error(ref err) => err.fmt(f),
Error::NulError(ref err) => err.fmt(f),
Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
Error::ExecuteReturnedResults => {
Self::Utf8Error(ref err) => err.fmt(f),
Self::NulError(ref err) => err.fmt(f),
Self::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
Self::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
Self::ExecuteReturnedResults => {
write!(f, "Execute returned results - did you mean to call query?")
}
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
Error::InvalidColumnType(i, ref name, ref t) => {
Self::QueryReturnedNoRows => write!(f, "Query returned no rows"),
Self::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
Self::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
Self::InvalidColumnType(i, ref name, ref t) => {
write!(f, "Invalid column type {t} at index: {i}, name: {name}")
}
Error::ArrowTypeToDuckdbType(ref name, ref t) => {
Self::ArrowTypeToDuckdbType(ref name, ref t) => {
write!(f, "Invalid column type {t} , name: {name}")
}
Error::InvalidParameterCount(i1, n1) => {
Self::InvalidParameterCount(i1, n1) => {
write!(f, "Wrong number of parameters passed to query. Got {i1}, needed {n1}")
}
Error::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
Error::ToSqlConversionFailure(ref err) => err.fmt(f),
Error::InvalidQuery => write!(f, "Query is not read-only"),
Error::MultipleStatement => write!(f, "Multiple statements provided"),
Error::AppendError => write!(f, "Append error"),
Self::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
Self::ToSqlConversionFailure(ref err) => err.fmt(f),
Self::InvalidQuery => write!(f, "Query is not read-only"),
Self::MultipleStatement => write!(f, "Multiple statements provided"),
Self::AppendError => write!(f, "Append error"),
}
}
}

impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
Error::DuckDBFailure(ref err, _) => Some(err),
Error::Utf8Error(ref err) => Some(err),
Error::NulError(ref err) => Some(err),

Error::IntegralValueOutOfRange(..)
| Error::InvalidParameterName(_)
| Error::ExecuteReturnedResults
| Error::QueryReturnedNoRows
| Error::InvalidColumnIndex(_)
| Error::InvalidColumnName(_)
| Error::InvalidColumnType(..)
| Error::InvalidPath(_)
| Error::InvalidParameterCount(..)
| Error::StatementChangedRows(_)
| Error::InvalidQuery
| Error::AppendError
| Error::ArrowTypeToDuckdbType(..)
| Error::MultipleStatement => None,
Error::FromSqlConversionFailure(_, _, ref err) | Error::ToSqlConversionFailure(ref err) => Some(&**err),
Self::DuckDBFailure(ref err, _) => Some(err),
Self::Utf8Error(ref err) => Some(err),
Self::NulError(ref err) => Some(err),

Self::IntegralValueOutOfRange(..)
| Self::InvalidParameterName(_)
| Self::ExecuteReturnedResults
| Self::QueryReturnedNoRows
| Self::InvalidColumnIndex(_)
| Self::InvalidColumnName(_)
| Self::InvalidColumnType(..)
| Self::InvalidPath(_)
| Self::InvalidParameterCount(..)
| Self::StatementChangedRows(_)
| Self::InvalidQuery
| Self::AppendError
| Self::ArrowTypeToDuckdbType(..)
| Self::MultipleStatement => None,
Self::FromSqlConversionFailure(_, _, ref err) | Self::ToSqlConversionFailure(ref err) => Some(&**err),
}
}
}
Expand Down
Loading
Loading