Skip to content

Commit 4a36675

Browse files
authored
chore: Replace TryInto impl by TryFrom (#21203)
`TryInto` is automatically implemented using `TryFrom` leading to a common convention to only implement `TryFrom` explicitly This does not break the API outside of adding a new `TryFrom` implementation
1 parent 11c2fbc commit 4a36675

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

datafusion/common/src/config.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,30 +1260,30 @@ config_namespace! {
12601260
}
12611261
}
12621262

1263-
impl<'a> TryInto<arrow::util::display::FormatOptions<'a>> for &'a FormatOptions {
1263+
impl<'a> TryFrom<&'a FormatOptions> for arrow::util::display::FormatOptions<'a> {
12641264
type Error = DataFusionError;
1265-
fn try_into(self) -> Result<arrow::util::display::FormatOptions<'a>> {
1266-
let duration_format = match self.duration_format.as_str() {
1265+
fn try_from(options: &'a FormatOptions) -> Result<Self> {
1266+
let duration_format = match options.duration_format.as_str() {
12671267
"pretty" => arrow::util::display::DurationFormat::Pretty,
12681268
"iso8601" => arrow::util::display::DurationFormat::ISO8601,
12691269
_ => {
12701270
return _config_err!(
12711271
"Invalid duration format: {}. Valid values are pretty or iso8601",
1272-
self.duration_format
1272+
options.duration_format
12731273
);
12741274
}
12751275
};
12761276

1277-
Ok(arrow::util::display::FormatOptions::new()
1278-
.with_display_error(self.safe)
1279-
.with_null(&self.null)
1280-
.with_date_format(self.date_format.as_deref())
1281-
.with_datetime_format(self.datetime_format.as_deref())
1282-
.with_timestamp_format(self.timestamp_format.as_deref())
1283-
.with_timestamp_tz_format(self.timestamp_tz_format.as_deref())
1284-
.with_time_format(self.time_format.as_deref())
1277+
Ok(Self::new()
1278+
.with_display_error(options.safe)
1279+
.with_null(&options.null)
1280+
.with_date_format(options.date_format.as_deref())
1281+
.with_datetime_format(options.datetime_format.as_deref())
1282+
.with_timestamp_format(options.timestamp_format.as_deref())
1283+
.with_timestamp_tz_format(options.timestamp_tz_format.as_deref())
1284+
.with_time_format(options.time_format.as_deref())
12851285
.with_duration_format(duration_format)
1286-
.with_types_info(self.types_info))
1286+
.with_types_info(options.types_info))
12871287
}
12881288
}
12891289

datafusion/proto-common/src/from_proto/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717

1818
use std::collections::HashMap;
19-
use std::convert::{TryFrom, TryInto};
2019
use std::sync::Arc;
2120

2221
use crate::common::proto_error;

0 commit comments

Comments
 (0)