[
https://issues.apache.org/jira/browse/ARROW-2415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16429526#comment-16429526
]
ASF GitHub Bot commented on ARROW-2415:
---------------------------------------
maxim-lian commented on issue #1851: ARROW-2415: [Rust] Fix clippy
ref-match-pats warnings.
URL: https://github.com/apache/arrow/pull/1851#issuecomment-379492997
This is (almost) all the remainder of them:
```diff
diff --git a/rust/src/array.rs b/rust/src/array.rs
index 09f0c950..e6ee0241 100644
--- a/rust/src/array.rs
+++ b/rust/src/array.rs
@@ -93,6 +93,9 @@ impl Array {
pub fn len(&self) -> usize {
self.len as usize
}
+ pub fn is_empty(&self) -> bool {
+ self.len == 0
+}
}
macro_rules! array_from_primitive {
@@ -137,8 +140,8 @@ macro_rules! array_from_optional_primitive {
fn from(v: Vec<Option<$DT>>) -> Self {
let mut null_count = 0;
let mut validity_bitmap = Bitmap::new(v.len());
- for i in 0..v.len() {
- if v[i].is_none() {
+ for (i, item) in v.iter().enumerate() {
+ if item.is_none() {
null_count += 1;
validity_bitmap.clear(i);
}
@@ -192,7 +195,7 @@ impl From<Vec<Rc<Array>>> for Array {
len: v.len() as i32,
null_count: 0,
validity_bitmap: None,
- data: ArrayData::Struct(v.iter().map(|a| a.clone()).collect()),
+ data: ArrayData::Struct(v.iter().cloned().collect()),
}
}
}
diff --git a/rust/src/bitmap.rs b/rust/src/bitmap.rs
index 59c65139..264feb4f 100644
--- a/rust/src/bitmap.rs
+++ b/rust/src/bitmap.rs
@@ -42,6 +42,9 @@ impl Bitmap {
pub fn len(&self) -> i32 {
self.bits.len()
}
+ pub fn is_empty(&self) -> bool {
+ self.len() == 0
+ }
pub fn is_set(&self, i: usize) -> bool {
let byte_offset = i / 8;
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 1f2ec6c8..a4907e61 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -38,6 +38,9 @@ impl<T> Buffer<T> {
self.len
}
+ pub fn is_empty(&self) -> bool {
+ self.len == 0
+ }
pub fn data(&self) -> *const T {
self.data
}
@@ -166,6 +169,7 @@ mod tests {
fn test_buffer_i32() {
let b: Buffer<i32> = Buffer::from(vec![1, 2, 3, 4, 5]);
assert_eq!(5, b.len);
+ assert_eq!(false, b.is_empty());
}
#[test]
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index ac2c2c6e..19e85321 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -40,17 +40,17 @@ pub enum DataType {
impl DataType {
fn from(json: &Value) -> Result<DataType, ArrowError> {
//println!("DataType::from({:?})", json);
- match json {
- &Value::Object(ref map) => match map.get("name") {
+ match *json {
+ Value::Object(ref map) => match map.get("name") {
Some(s) if s == "bool" => Ok(DataType::Boolean),
Some(s) if s == "utf8" => Ok(DataType::Utf8),
Some(s) if s == "floatingpoint" => match
map.get("precision") {
Some(p) if p == "HALF" => Ok(DataType::Float16),
Some(p) if p == "SINGLE" => Ok(DataType::Float32),
Some(p) if p == "DOUBLE" => Ok(DataType::Float64),
- _ => Err(ArrowError::ParseError(format!(
- "floatingpoint precision missing or invalid"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "floatingpoint precision missing or
invalid".to_string(),
+ )),
},
Some(s) if s == "int" => match map.get("isSigned") {
Some(&Value::Bool(true)) => match map.get("bitWidth") {
@@ -59,13 +59,13 @@ impl DataType {
Some(16) => Ok(DataType::Int16),
Some(32) => Ok(DataType::Int32),
Some(64) => Ok(DataType::Int32),
- _ => Err(ArrowError::ParseError(format!(
- "int bitWidth missing or invalid"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "int bitWidth missing or
invalid".to_string(),
+ )),
},
- _ => Err(ArrowError::ParseError(format!(
- "int bitWidth missing or invalid"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "int bitWidth missing or invalid".to_string(),
+ )),
},
Some(&Value::Bool(false)) => match map.get("bitWidth") {
Some(&Value::Number(ref n)) => match n.as_u64() {
@@ -73,17 +73,17 @@ impl DataType {
Some(16) => Ok(DataType::UInt16),
Some(32) => Ok(DataType::UInt32),
Some(64) => Ok(DataType::UInt64),
- _ => Err(ArrowError::ParseError(format!(
- "int bitWidth missing or invalid"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "int bitWidth missing or
invalid".to_string(),
+ )),
},
- _ => Err(ArrowError::ParseError(format!(
- "int bitWidth missing or invalid"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "int bitWidth missing or invalid".to_string(),
+ )),
},
- _ => Err(ArrowError::ParseError(format!(
- "int signed missing or invalid"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "int signed missing or invalid".to_string(),
+ )),
},
Some(other) => Err(ArrowError::ParseError(format!(
"invalid type name: {}",
@@ -97,29 +97,31 @@ impl DataType {
.collect::<Result<Vec<Field>, ArrowError>>();
Ok(DataType::Struct(fields?))
}
- _ => Err(ArrowError::ParseError(format!("empty type"))),
+ _ => Err(ArrowError::ParseError("empty
type".to_string())),
},
},
- _ => Err(ArrowError::ParseError(format!("invalid json value
type"))),
+ _ => Err(ArrowError::ParseError(
+ "invalid json value type".to_string(),
+ )),
}
}
pub fn to_json(&self) -> Value {
- match self {
- &DataType::Boolean => json!({"name": "bool"}),
- &DataType::Int8 => json!({"name": "int", "bitWidth": 8,
"isSigned": true}),
- &DataType::Int16 => json!({"name": "int", "bitWidth": 16,
"isSigned": true}),
- &DataType::Int32 => json!({"name": "int", "bitWidth": 32,
"isSigned": true}),
- &DataType::Int64 => json!({"name": "int", "bitWidth": 64,
"isSigned": true}),
- &DataType::UInt8 => json!({"name": "int", "bitWidth": 8,
"isSigned": false}),
- &DataType::UInt16 => json!({"name": "int", "bitWidth": 16,
"isSigned": false}),
- &DataType::UInt32 => json!({"name": "int", "bitWidth": 32,
"isSigned": false}),
- &DataType::UInt64 => json!({"name": "int", "bitWidth": 64,
"isSigned": false}),
- &DataType::Float16 => json!({"name": "floatingpoint",
"precision": "HALF"}),
- &DataType::Float32 => json!({"name": "floatingpoint",
"precision": "SINGLE"}),
- &DataType::Float64 => json!({"name": "floatingpoint",
"precision": "DOUBLE"}),
- &DataType::Utf8 => json!({"name": "utf8"}),
- &DataType::Struct(ref fields) => {
+ match *self {
+ DataType::Boolean => json!({"name": "bool"}),
+ DataType::Int8 => json!({"name": "int", "bitWidth": 8,
"isSigned": true}),
+ DataType::Int16 => json!({"name": "int", "bitWidth": 16,
"isSigned": true}),
+ DataType::Int32 => json!({"name": "int", "bitWidth": 32,
"isSigned": true}),
+ DataType::Int64 => json!({"name": "int", "bitWidth": 64,
"isSigned": true}),
+ DataType::UInt8 => json!({"name": "int", "bitWidth": 8,
"isSigned": false}),
+ DataType::UInt16 => json!({"name": "int", "bitWidth": 16,
"isSigned": false}),
+ DataType::UInt32 => json!({"name": "int", "bitWidth": 32,
"isSigned": false}),
+ DataType::UInt64 => json!({"name": "int", "bitWidth": 64,
"isSigned": false}),
+ DataType::Float16 => json!({"name": "floatingpoint",
"precision": "HALF"}),
+ DataType::Float32 => json!({"name": "floatingpoint",
"precision": "SINGLE"}),
+ DataType::Float64 => json!({"name": "floatingpoint",
"precision": "DOUBLE"}),
+ DataType::Utf8 => json!({"name": "utf8"}),
+ DataType::Struct(ref fields) => {
let field_json_array =
Value::Array(fields.iter().map(|f|
f.to_json()).collect::<Vec<Value>>());
json!({ "fields": field_json_array })
@@ -139,37 +141,37 @@ impl Field {
pub fn new(name: &str, data_type: DataType, nullable: bool) -> Self {
Field {
name: name.to_string(),
- data_type: data_type,
- nullable: nullable,
+ data_type,
+ nullable,
}
}
pub fn from(json: &Value) -> Result<Self, ArrowError> {
//println!("Field::from({:?}", json);
- match json {
- &Value::Object(ref map) => {
+ match *json {
+ Value::Object(ref map) => {
let name = match map.get("name") {
Some(&Value::String(ref name)) => name.to_string(),
_ => {
- return Err(ArrowError::ParseError(format!(
- "Field missing 'name' attribute"
- )))
+ return Err(ArrowError::ParseError(
+ "Field missing 'name' attribute".to_string(),
+ ))
}
};
let nullable = match map.get("nullable") {
Some(&Value::Bool(b)) => b,
_ => {
- return Err(ArrowError::ParseError(format!(
- "Field missing 'nullable' attribute"
- )))
+ return Err(ArrowError::ParseError(
+ "Field missing 'nullable'
attribute".to_string(),
+ ))
}
};
let data_type = match map.get("type") {
Some(t) => DataType::from(t)?,
_ => {
- return Err(ArrowError::ParseError(format!(
- "Field missing 'type' attribute"
- )))
+ return Err(ArrowError::ParseError(
+ "Field missing 'type' attribute".to_string(),
+ ))
}
};
Ok(Field {
@@ -178,9 +180,9 @@ impl Field {
data_type,
})
}
- _ => Err(ArrowError::ParseError(format!(
- "Invalid json value type for field"
- ))),
+ _ => Err(ArrowError::ParseError(
+ "Invalid json value type for field".to_string(),
+ )),
}
}
@@ -215,7 +217,7 @@ impl Schema {
}
pub fn new(columns: Vec<Field>) -> Self {
- Schema { columns: columns }
+ Schema { columns }
}
/// look up a column by name and return a reference to the column along
with it's index
diff --git a/rust/src/list.rs b/rust/src/list.rs
index 461f8e64..c46d1ef9 100644
--- a/rust/src/list.rs
+++ b/rust/src/list.rs
@@ -31,10 +31,14 @@ impl<T> List<T> {
self.offsets.len() - 1
}
+ pub fn is_empty(&self) -> bool {
+ self.len() == 0
+ }
+
pub fn slice(&self, index: usize) -> &[T] {
let start = *self.offsets.get(index) as usize;
let end = *self.offsets.get(index + 1) as usize;
- &self.data.slice(start, end)
+ self.data.slice(start, end)
}
}
diff --git a/rust/src/memory.rs b/rust/src/memory.rs
index 41d4c53e..e3bb786b 100644
--- a/rust/src/memory.rs
+++ b/rust/src/memory.rs
@@ -28,9 +28,9 @@ pub fn allocate_aligned(size: i64) -> Result<*const u8,
ArrowError> {
let result = libc::posix_memalign(&mut page, ALIGNMENT, size as
usize);
match result {
0 => Ok(mem::transmute::<*mut libc::c_void, *const u8>(page)),
- _ => Err(ArrowError::MemoryError(format!(
- "Failed to allocate memory"
- ))),
+ _ => Err(ArrowError::MemoryError(
+ "Failed to allocate memory".to_string(),
+ )),
}
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [Rust] Fix using references in pattern matching
> -----------------------------------------------
>
> Key: ARROW-2415
> URL: https://issues.apache.org/jira/browse/ARROW-2415
> Project: Apache Arrow
> Issue Type: Improvement
> Components: Rust
> Reporter: Bruce Mitchener
> Priority: Major
> Labels: pull-request-available
>
> Clippy reports
> [https://rust-lang-nursery.github.io/rust-clippy/v0.0.191/index.html#match_ref_pats]
> warnings.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)