Skip to content

Commit c24374c

Browse files
authored
ran cargo clippy --fix -- -Wclippy::use_self (#502)
1 parent 92e0a5d commit c24374c

File tree

19 files changed

+251
-251
lines changed

19 files changed

+251
-251
lines changed

crates/duckdb/src/arrow_batch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Arrow<'stmt> {
1212
#[allow(clippy::needless_lifetimes)]
1313
impl<'stmt> Arrow<'stmt> {
1414
#[inline]
15-
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Arrow<'stmt> {
15+
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Self {
1616
Arrow { stmt: Some(stmt) }
1717
}
1818

@@ -43,7 +43,7 @@ pub struct ArrowStream<'stmt> {
4343
#[allow(clippy::needless_lifetimes)]
4444
impl<'stmt> ArrowStream<'stmt> {
4545
#[inline]
46-
pub(crate) fn new(stmt: &'stmt Statement<'stmt>, schema: SchemaRef) -> ArrowStream<'stmt> {
46+
pub(crate) fn new(stmt: &'stmt Statement<'stmt>, schema: SchemaRef) -> Self {
4747
ArrowStream {
4848
stmt: Some(stmt),
4949
schema,

crates/duckdb/src/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl CachedStatement<'_> {
120120
impl StatementCache {
121121
/// Create a statement cache.
122122
#[inline]
123-
pub fn with_capacity(capacity: usize) -> StatementCache {
124-
StatementCache(RefCell::new(LruCache::new(capacity)))
123+
pub fn with_capacity(capacity: usize) -> Self {
124+
Self(RefCell::new(LruCache::new(capacity)))
125125
}
126126

127127
#[inline]

crates/duckdb/src/config.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,69 +53,69 @@ impl Config {
5353
}
5454

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

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

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

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

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

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

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

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

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

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

116116
/// Add any setting to the config. DuckDB will return an error if the setting is unknown or
117117
/// otherwise invalid.
118-
pub fn with(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Result<Config> {
118+
pub fn with(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Result<Self> {
119119
self.set(key.as_ref(), value.as_ref())?;
120120
Ok(self)
121121
}

crates/duckdb/src/core/data_chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl DataChunkHandle {
3636
let num_columns = logical_types.len();
3737
let mut c_types = logical_types.iter().map(|t| t.ptr).collect::<Vec<_>>();
3838
let ptr = unsafe { duckdb_create_data_chunk(c_types.as_mut_ptr(), num_columns as u64) };
39-
DataChunkHandle { ptr, owned: true }
39+
Self { ptr, owned: true }
4040
}
4141

4242
/// Get the vector at the specific column index: `idx`.

crates/duckdb/src/core/logical_type.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl LogicalTypeHandle {
165165
}
166166

167167
/// Creates a map type from its child type.
168-
pub fn map(key: &LogicalTypeHandle, value: &LogicalTypeHandle) -> Self {
168+
pub fn map(key: &Self, value: &Self) -> Self {
169169
unsafe {
170170
Self {
171171
ptr: duckdb_create_map_type(key.ptr, value.ptr),
@@ -174,7 +174,7 @@ impl LogicalTypeHandle {
174174
}
175175

176176
/// Creates a list type from its child type.
177-
pub fn list(child_type: &LogicalTypeHandle) -> Self {
177+
pub fn list(child_type: &Self) -> Self {
178178
unsafe {
179179
Self {
180180
ptr: duckdb_create_list_type(child_type.ptr),
@@ -183,7 +183,7 @@ impl LogicalTypeHandle {
183183
}
184184

185185
/// Creates an array type from its child type.
186-
pub fn array(child_type: &LogicalTypeHandle, array_size: u64) -> Self {
186+
pub fn array(child_type: &Self, array_size: u64) -> Self {
187187
unsafe {
188188
Self {
189189
ptr: duckdb_create_array_type(child_type.ptr, array_size),
@@ -213,7 +213,7 @@ impl LogicalTypeHandle {
213213
}
214214

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

232232
/// Make a `LogicalType` for `union`
233-
pub fn union_type(fields: &[(&str, LogicalTypeHandle)]) -> Self {
233+
pub fn union_type(fields: &[(&str, Self)]) -> Self {
234234
let keys: Vec<CString> = fields.iter().map(|f| CString::new(f.0).unwrap()).collect();
235235
let values: Vec<duckdb_logical_type> = fields.iter().map(|it| it.1.ptr).collect();
236236
let name_ptrs = keys.iter().map(|it| it.as_ptr()).collect::<Vec<*const c_char>>();

crates/duckdb/src/core/vector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ impl ListVector {
215215
}
216216

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

222222
/// Set primitive data to the child node.
@@ -321,7 +321,7 @@ impl StructVector {
321321
}
322322

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

crates/duckdb/src/error.rs

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -86,39 +86,39 @@ pub enum Error {
8686
}
8787

8888
impl PartialEq for Error {
89-
fn eq(&self, other: &Error) -> bool {
89+
fn eq(&self, other: &Self) -> bool {
9090
match (self, other) {
91-
(Error::DuckDBFailure(e1, s1), Error::DuckDBFailure(e2, s2)) => e1 == e2 && s1 == s2,
92-
(Error::IntegralValueOutOfRange(i1, n1), Error::IntegralValueOutOfRange(i2, n2)) => i1 == i2 && n1 == n2,
93-
(Error::Utf8Error(e1), Error::Utf8Error(e2)) => e1 == e2,
94-
(Error::NulError(e1), Error::NulError(e2)) => e1 == e2,
95-
(Error::InvalidParameterName(n1), Error::InvalidParameterName(n2)) => n1 == n2,
96-
(Error::InvalidPath(p1), Error::InvalidPath(p2)) => p1 == p2,
97-
(Error::ExecuteReturnedResults, Error::ExecuteReturnedResults) => true,
98-
(Error::QueryReturnedNoRows, Error::QueryReturnedNoRows) => true,
99-
(Error::InvalidColumnIndex(i1), Error::InvalidColumnIndex(i2)) => i1 == i2,
100-
(Error::InvalidColumnName(n1), Error::InvalidColumnName(n2)) => n1 == n2,
101-
(Error::InvalidColumnType(i1, n1, t1), Error::InvalidColumnType(i2, n2, t2)) => {
91+
(Self::DuckDBFailure(e1, s1), Self::DuckDBFailure(e2, s2)) => e1 == e2 && s1 == s2,
92+
(Self::IntegralValueOutOfRange(i1, n1), Self::IntegralValueOutOfRange(i2, n2)) => i1 == i2 && n1 == n2,
93+
(Self::Utf8Error(e1), Self::Utf8Error(e2)) => e1 == e2,
94+
(Self::NulError(e1), Self::NulError(e2)) => e1 == e2,
95+
(Self::InvalidParameterName(n1), Self::InvalidParameterName(n2)) => n1 == n2,
96+
(Self::InvalidPath(p1), Self::InvalidPath(p2)) => p1 == p2,
97+
(Self::ExecuteReturnedResults, Self::ExecuteReturnedResults) => true,
98+
(Self::QueryReturnedNoRows, Self::QueryReturnedNoRows) => true,
99+
(Self::InvalidColumnIndex(i1), Self::InvalidColumnIndex(i2)) => i1 == i2,
100+
(Self::InvalidColumnName(n1), Self::InvalidColumnName(n2)) => n1 == n2,
101+
(Self::InvalidColumnType(i1, n1, t1), Self::InvalidColumnType(i2, n2, t2)) => {
102102
i1 == i2 && t1 == t2 && n1 == n2
103103
}
104-
(Error::StatementChangedRows(n1), Error::StatementChangedRows(n2)) => n1 == n2,
105-
(Error::InvalidParameterCount(i1, n1), Error::InvalidParameterCount(i2, n2)) => i1 == i2 && n1 == n2,
104+
(Self::StatementChangedRows(n1), Self::StatementChangedRows(n2)) => n1 == n2,
105+
(Self::InvalidParameterCount(i1, n1), Self::InvalidParameterCount(i2, n2)) => i1 == i2 && n1 == n2,
106106
(..) => false,
107107
}
108108
}
109109
}
110110

111111
impl From<str::Utf8Error> for Error {
112112
#[cold]
113-
fn from(err: str::Utf8Error) -> Error {
114-
Error::Utf8Error(err)
113+
fn from(err: str::Utf8Error) -> Self {
114+
Self::Utf8Error(err)
115115
}
116116
}
117117

118118
impl From<::std::ffi::NulError> for Error {
119119
#[cold]
120-
fn from(err: ::std::ffi::NulError) -> Error {
121-
Error::NulError(err)
120+
fn from(err: ::std::ffi::NulError) -> Self {
121+
Self::NulError(err)
122122
}
123123
}
124124

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

146146
impl fmt::Display for Error {
147147
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148148
match *self {
149-
Error::DuckDBFailure(ref err, None) => err.fmt(f),
150-
Error::DuckDBFailure(_, Some(ref s)) => write!(f, "{s}"),
151-
Error::FromSqlConversionFailure(i, ref t, ref err) => {
149+
Self::DuckDBFailure(ref err, None) => err.fmt(f),
150+
Self::DuckDBFailure(_, Some(ref s)) => write!(f, "{s}"),
151+
Self::FromSqlConversionFailure(i, ref t, ref err) => {
152152
if i != UNKNOWN_COLUMN {
153153
write!(f, "Conversion error from type {t} at index: {i}, {err}")
154154
} else {
155155
err.fmt(f)
156156
}
157157
}
158-
Error::IntegralValueOutOfRange(col, val) => {
158+
Self::IntegralValueOutOfRange(col, val) => {
159159
if col != UNKNOWN_COLUMN {
160160
write!(f, "Integer {val} out of range at index {col}")
161161
} else {
162162
write!(f, "Integer {val} out of range")
163163
}
164164
}
165-
Error::Utf8Error(ref err) => err.fmt(f),
166-
Error::NulError(ref err) => err.fmt(f),
167-
Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
168-
Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
169-
Error::ExecuteReturnedResults => {
165+
Self::Utf8Error(ref err) => err.fmt(f),
166+
Self::NulError(ref err) => err.fmt(f),
167+
Self::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
168+
Self::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
169+
Self::ExecuteReturnedResults => {
170170
write!(f, "Execute returned results - did you mean to call query?")
171171
}
172-
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
173-
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
174-
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
175-
Error::InvalidColumnType(i, ref name, ref t) => {
172+
Self::QueryReturnedNoRows => write!(f, "Query returned no rows"),
173+
Self::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
174+
Self::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
175+
Self::InvalidColumnType(i, ref name, ref t) => {
176176
write!(f, "Invalid column type {t} at index: {i}, name: {name}")
177177
}
178-
Error::ArrowTypeToDuckdbType(ref name, ref t) => {
178+
Self::ArrowTypeToDuckdbType(ref name, ref t) => {
179179
write!(f, "Invalid column type {t} , name: {name}")
180180
}
181-
Error::InvalidParameterCount(i1, n1) => {
181+
Self::InvalidParameterCount(i1, n1) => {
182182
write!(f, "Wrong number of parameters passed to query. Got {i1}, needed {n1}")
183183
}
184-
Error::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
185-
Error::ToSqlConversionFailure(ref err) => err.fmt(f),
186-
Error::InvalidQuery => write!(f, "Query is not read-only"),
187-
Error::MultipleStatement => write!(f, "Multiple statements provided"),
188-
Error::AppendError => write!(f, "Append error"),
184+
Self::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
185+
Self::ToSqlConversionFailure(ref err) => err.fmt(f),
186+
Self::InvalidQuery => write!(f, "Query is not read-only"),
187+
Self::MultipleStatement => write!(f, "Multiple statements provided"),
188+
Self::AppendError => write!(f, "Append error"),
189189
}
190190
}
191191
}
192192

193193
impl error::Error for Error {
194194
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
195195
match *self {
196-
Error::DuckDBFailure(ref err, _) => Some(err),
197-
Error::Utf8Error(ref err) => Some(err),
198-
Error::NulError(ref err) => Some(err),
199-
200-
Error::IntegralValueOutOfRange(..)
201-
| Error::InvalidParameterName(_)
202-
| Error::ExecuteReturnedResults
203-
| Error::QueryReturnedNoRows
204-
| Error::InvalidColumnIndex(_)
205-
| Error::InvalidColumnName(_)
206-
| Error::InvalidColumnType(..)
207-
| Error::InvalidPath(_)
208-
| Error::InvalidParameterCount(..)
209-
| Error::StatementChangedRows(_)
210-
| Error::InvalidQuery
211-
| Error::AppendError
212-
| Error::ArrowTypeToDuckdbType(..)
213-
| Error::MultipleStatement => None,
214-
Error::FromSqlConversionFailure(_, _, ref err) | Error::ToSqlConversionFailure(ref err) => Some(&**err),
196+
Self::DuckDBFailure(ref err, _) => Some(err),
197+
Self::Utf8Error(ref err) => Some(err),
198+
Self::NulError(ref err) => Some(err),
199+
200+
Self::IntegralValueOutOfRange(..)
201+
| Self::InvalidParameterName(_)
202+
| Self::ExecuteReturnedResults
203+
| Self::QueryReturnedNoRows
204+
| Self::InvalidColumnIndex(_)
205+
| Self::InvalidColumnName(_)
206+
| Self::InvalidColumnType(..)
207+
| Self::InvalidPath(_)
208+
| Self::InvalidParameterCount(..)
209+
| Self::StatementChangedRows(_)
210+
| Self::InvalidQuery
211+
| Self::AppendError
212+
| Self::ArrowTypeToDuckdbType(..)
213+
| Self::MultipleStatement => None,
214+
Self::FromSqlConversionFailure(_, _, ref err) | Self::ToSqlConversionFailure(ref err) => Some(&**err),
215215
}
216216
}
217217
}

0 commit comments

Comments
 (0)