Skip to content

Commit 5d2084b

Browse files
chore: Format examples in doc strings - common (#18336)
## Which issue does this PR close? Part of #16915 ## Rationale for this change Format code examples in documentation comments to improve readability and maintain consistent code style across the codebase. This is part of a multi-PR effort to format all doc comment examples and eventually enable CI checks to enforce this formatting. ## What changes are included in this PR? Run `cargo fmt -p datafusion-common -- --config format_code_in_doc_comments=true` ## Are these changes tested? No testing needed - this is purely a formatting change with no functional modifications. ## Are there any user-facing changes? No - this only affects documentation formatting.
1 parent ddf49c7 commit 5d2084b

File tree

17 files changed

+232
-208
lines changed

17 files changed

+232
-208
lines changed

datafusion/common/src/config.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use std::sync::Arc;
5757
/// /// Field 3 doc
5858
/// field3: Option<usize>, default = None
5959
/// }
60-
///}
60+
/// }
6161
/// ```
6262
///
6363
/// Will generate
@@ -1326,36 +1326,35 @@ impl ConfigOptions {
13261326
/// # Example
13271327
/// ```
13281328
/// use datafusion_common::{
1329-
/// config::ConfigExtension, extensions_options,
1330-
/// config::ConfigOptions,
1329+
/// config::ConfigExtension, config::ConfigOptions, extensions_options,
13311330
/// };
1332-
/// // Define a new configuration struct using the `extensions_options` macro
1333-
/// extensions_options! {
1334-
/// /// My own config options.
1335-
/// pub struct MyConfig {
1336-
/// /// Should "foo" be replaced by "bar"?
1337-
/// pub foo_to_bar: bool, default = true
1331+
/// // Define a new configuration struct using the `extensions_options` macro
1332+
/// extensions_options! {
1333+
/// /// My own config options.
1334+
/// pub struct MyConfig {
1335+
/// /// Should "foo" be replaced by "bar"?
1336+
/// pub foo_to_bar: bool, default = true
13381337
///
1339-
/// /// How many "baz" should be created?
1340-
/// pub baz_count: usize, default = 1337
1341-
/// }
1342-
/// }
1338+
/// /// How many "baz" should be created?
1339+
/// pub baz_count: usize, default = 1337
1340+
/// }
1341+
/// }
13431342
///
1344-
/// impl ConfigExtension for MyConfig {
1343+
/// impl ConfigExtension for MyConfig {
13451344
/// const PREFIX: &'static str = "my_config";
1346-
/// }
1345+
/// }
13471346
///
1348-
/// // set up config struct and register extension
1349-
/// let mut config = ConfigOptions::default();
1350-
/// config.extensions.insert(MyConfig::default());
1347+
/// // set up config struct and register extension
1348+
/// let mut config = ConfigOptions::default();
1349+
/// config.extensions.insert(MyConfig::default());
13511350
///
1352-
/// // overwrite config default
1353-
/// config.set("my_config.baz_count", "42").unwrap();
1351+
/// // overwrite config default
1352+
/// config.set("my_config.baz_count", "42").unwrap();
13541353
///
1355-
/// // check config state
1356-
/// let my_config = config.extensions.get::<MyConfig>().unwrap();
1357-
/// assert!(my_config.foo_to_bar,);
1358-
/// assert_eq!(my_config.baz_count, 42,);
1354+
/// // check config state
1355+
/// let my_config = config.extensions.get::<MyConfig>().unwrap();
1356+
/// assert!(my_config.foo_to_bar,);
1357+
/// assert_eq!(my_config.baz_count, 42,);
13591358
/// ```
13601359
///
13611360
/// # Note:

datafusion/common/src/datatype.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub trait FieldExt {
8181
/// assert_eq!(list_field.data_type(), &DataType::List(Arc::new(
8282
/// Field::new("item", DataType::Int32, true)
8383
/// )));
84-
///
8584
fn into_list(self) -> Self;
8685

8786
/// Return a new Field representing this Field as the item type of a
@@ -107,7 +106,6 @@ pub trait FieldExt {
107106
/// Field::new("item", DataType::Int32, true)),
108107
/// 3
109108
/// ));
110-
///
111109
fn into_fixed_size_list(self, list_size: i32) -> Self;
112110

113111
/// Update the field to have the default list field name ("item")

datafusion/common/src/dfschema.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ pub type DFSchemaRef = Arc<DFSchema>;
5656
/// an Arrow schema.
5757
///
5858
/// ```rust
59-
/// use datafusion_common::{DFSchema, Column};
6059
/// use arrow::datatypes::{DataType, Field, Schema};
60+
/// use datafusion_common::{Column, DFSchema};
6161
///
62-
/// let arrow_schema = Schema::new(vec![
63-
/// Field::new("c1", DataType::Int32, false),
64-
/// ]);
62+
/// let arrow_schema = Schema::new(vec![Field::new("c1", DataType::Int32, false)]);
6563
///
6664
/// let df_schema = DFSchema::try_from_qualified_schema("t1", &arrow_schema).unwrap();
6765
/// let column = Column::from_qualified_name("t1.c1");
@@ -77,12 +75,10 @@ pub type DFSchemaRef = Arc<DFSchema>;
7775
/// Create an unqualified schema using TryFrom:
7876
///
7977
/// ```rust
80-
/// use datafusion_common::{DFSchema, Column};
8178
/// use arrow::datatypes::{DataType, Field, Schema};
79+
/// use datafusion_common::{Column, DFSchema};
8280
///
83-
/// let arrow_schema = Schema::new(vec![
84-
/// Field::new("c1", DataType::Int32, false),
85-
/// ]);
81+
/// let arrow_schema = Schema::new(vec![Field::new("c1", DataType::Int32, false)]);
8682
///
8783
/// let df_schema = DFSchema::try_from(arrow_schema).unwrap();
8884
/// let column = Column::new_unqualified("c1");
@@ -94,13 +90,15 @@ pub type DFSchemaRef = Arc<DFSchema>;
9490
/// Use the `Into` trait to convert `DFSchema` into an Arrow schema:
9591
///
9692
/// ```rust
93+
/// use arrow::datatypes::{Field, Schema};
9794
/// use datafusion_common::DFSchema;
98-
/// use arrow::datatypes::{Schema, Field};
9995
/// use std::collections::HashMap;
10096
///
101-
/// let df_schema = DFSchema::from_unqualified_fields(vec![
102-
/// Field::new("c1", arrow::datatypes::DataType::Int32, false),
103-
/// ].into(),HashMap::new()).unwrap();
97+
/// let df_schema = DFSchema::from_unqualified_fields(
98+
/// vec![Field::new("c1", arrow::datatypes::DataType::Int32, false)].into(),
99+
/// HashMap::new(),
100+
/// )
101+
/// .unwrap();
104102
/// let schema: &Schema = df_schema.as_arrow();
105103
/// assert_eq!(schema.fields().len(), 1);
106104
/// ```
@@ -884,22 +882,26 @@ impl DFSchema {
884882
/// # Example
885883
///
886884
/// ```
887-
/// use datafusion_common::DFSchema;
888885
/// use arrow::datatypes::{DataType, Field, Schema};
886+
/// use datafusion_common::DFSchema;
889887
/// use std::collections::HashMap;
890888
///
891889
/// let schema = DFSchema::from_unqualified_fields(
892890
/// vec![
893891
/// Field::new("id", DataType::Int32, false),
894892
/// Field::new("name", DataType::Utf8, true),
895-
/// ].into(),
896-
/// HashMap::new()
897-
/// ).unwrap();
893+
/// ]
894+
/// .into(),
895+
/// HashMap::new(),
896+
/// )
897+
/// .unwrap();
898898
///
899-
/// assert_eq!(schema.tree_string().to_string(),
900-
/// r#"root
899+
/// assert_eq!(
900+
/// schema.tree_string().to_string(),
901+
/// r#"root
901902
/// |-- id: int32 (nullable = false)
902-
/// |-- name: utf8 (nullable = true)"#);
903+
/// |-- name: utf8 (nullable = true)"#
904+
/// );
903905
/// ```
904906
pub fn tree_string(&self) -> impl Display + '_ {
905907
let mut result = String::from("root\n");

datafusion/common/src/diagnostic.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ use crate::Span;
3030
/// ```rust
3131
/// # use datafusion_common::{Location, Span, Diagnostic};
3232
/// let span = Some(Span {
33-
/// start: Location{ line: 2, column: 1 },
34-
/// end: Location{ line: 4, column: 15 }
33+
/// start: Location { line: 2, column: 1 },
34+
/// end: Location {
35+
/// line: 4,
36+
/// column: 15,
37+
/// },
3538
/// });
3639
/// let diagnostic = Diagnostic::new_error("Something went wrong", span)
3740
/// .with_help("Have you tried turning it on and off again?", None);

datafusion/common/src/error.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,10 @@ impl DataFusionError {
684684
/// let mut builder = DataFusionError::builder();
685685
/// builder.add_error(DataFusionError::Internal("foo".to_owned()));
686686
/// // ok_or returns the value if no errors have been added
687-
/// assert_contains!(builder.error_or(42).unwrap_err().to_string(), "Internal error: foo");
687+
/// assert_contains!(
688+
/// builder.error_or(42).unwrap_err().to_string(),
689+
/// "Internal error: foo"
690+
/// );
688691
/// ```
689692
#[derive(Debug, Default)]
690693
pub struct DataFusionErrorBuilder(Vec<DataFusionError>);
@@ -702,7 +705,10 @@ impl DataFusionErrorBuilder {
702705
/// # use datafusion_common::{assert_contains, DataFusionError};
703706
/// let mut builder = DataFusionError::builder();
704707
/// builder.add_error(DataFusionError::Internal("foo".to_owned()));
705-
/// assert_contains!(builder.error_or(42).unwrap_err().to_string(), "Internal error: foo");
708+
/// assert_contains!(
709+
/// builder.error_or(42).unwrap_err().to_string(),
710+
/// "Internal error: foo"
711+
/// );
706712
/// ```
707713
pub fn add_error(&mut self, error: DataFusionError) {
708714
self.0.push(error);
@@ -714,8 +720,11 @@ impl DataFusionErrorBuilder {
714720
/// ```
715721
/// # use datafusion_common::{assert_contains, DataFusionError};
716722
/// let builder = DataFusionError::builder()
717-
/// .with_error(DataFusionError::Internal("foo".to_owned()));
718-
/// assert_contains!(builder.error_or(42).unwrap_err().to_string(), "Internal error: foo");
723+
/// .with_error(DataFusionError::Internal("foo".to_owned()));
724+
/// assert_contains!(
725+
/// builder.error_or(42).unwrap_err().to_string(),
726+
/// "Internal error: foo"
727+
/// );
719728
/// ```
720729
pub fn with_error(mut self, error: DataFusionError) -> Self {
721730
self.0.push(error);

datafusion/common/src/metadata.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ pub fn format_type_and_metadata(
171171
/// // Add any metadata from `FieldMetadata` to `Field`
172172
/// let updated_field = metadata.add_to_field(field);
173173
/// ```
174-
///
175174
#[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
176175
pub struct FieldMetadata {
177176
/// The inner metadata of a literal expression, which is a map of string

datafusion/common/src/nested_struct.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,19 @@ fn cast_struct_column(
110110
/// temporal values are formatted when cast to strings.
111111
///
112112
/// ```
113-
/// use std::sync::Arc;
114-
/// use arrow::array::{Int64Array, ArrayRef};
113+
/// use arrow::array::{ArrayRef, Int64Array};
115114
/// use arrow::compute::CastOptions;
116115
/// use arrow::datatypes::{DataType, Field};
117116
/// use datafusion_common::nested_struct::cast_column;
117+
/// use std::sync::Arc;
118118
///
119119
/// let source: ArrayRef = Arc::new(Int64Array::from(vec![1, i64::MAX]));
120120
/// let target = Field::new("ints", DataType::Int32, true);
121121
/// // Permit lossy conversions by producing NULL on overflow instead of erroring
122-
/// let options = CastOptions { safe: true, ..Default::default() };
122+
/// let options = CastOptions {
123+
/// safe: true,
124+
/// ..Default::default()
125+
/// };
123126
/// let result = cast_column(&source, &target, &options).unwrap();
124127
/// assert!(result.is_null(1));
125128
/// ```

0 commit comments

Comments
 (0)