Skip to content

Commit 9317af9

Browse files
authored
Merge pull request #198 from estie-inc/refactor/unify-default-new-constructors
refactor(config): provide new() on public config types and unify Default/new convention
2 parents 179f9dc + aa16b49 commit 9317af9

8 files changed

Lines changed: 23 additions & 20 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ struct ExampleRow {
1414
value: String,
1515
}
1616

17-
let session_config = SessionConfig::default()
17+
let session_config = SessionConfig::new()
1818
.with_role("ROLE")
1919
.with_warehouse("WAREHOUSE")
2020
.with_database("DATABASE")
2121
.with_schema("SCHEMA");
2222

23-
let query_config = QueryConfig::default()
23+
let query_config = QueryConfig::new()
2424
// Client-side timeout for obtaining a query response.
2525
.with_query_response_timeout(std::time::Duration::from_secs(60));
2626

@@ -221,7 +221,7 @@ let proxy = ProxyConfig::new(
221221
)
222222
.with_basic_auth("proxy_user", "proxy_pass");
223223

224-
let transport = TransportConfig::default().with_proxy(proxy);
224+
let transport = TransportConfig::new().with_proxy(proxy);
225225
let client = Client::new(
226226
ClientConfig::new("USERNAME", "ACCOUNT", auth)
227227
.with_transport(transport),

examples/derive_from_row.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
4646
}
4747

4848
async fn async_main() -> Result<()> {
49-
let client = connect_with_configs(session_config(), QueryConfig::default())?;
49+
let client = connect_with_configs(session_config(), QueryConfig::new())?;
5050
let session = client.create_session().await?;
5151

5252
run_default_mapping_example(&session).await?;
@@ -201,7 +201,7 @@ fn session_config() -> SessionConfig {
201201
let database = env::var("SNOWFLAKE_DATABASE").ok();
202202
let schema = env::var("SNOWFLAKE_SCHEMA").ok();
203203

204-
let mut session_config = SessionConfig::default();
204+
let mut session_config = SessionConfig::new();
205205
if let Some(warehouse) = warehouse {
206206
session_config = session_config.with_warehouse(warehouse);
207207
}

examples/external_browser_sso.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1313
let database = env::var("SNOWFLAKE_DATABASE").ok();
1414
let schema = env::var("SNOWFLAKE_SCHEMA").ok();
1515

16-
let mut session_config = SessionConfig::default();
16+
let mut session_config = SessionConfig::new();
1717
if let Some(warehouse) = warehouse {
1818
session_config = session_config.with_warehouse(warehouse);
1919
}

examples/external_browser_sso_without_callback_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1515
let external_browser =
1616
ExternalBrowserConfig::manual_redirect(BrowserLaunchMode::Manual, redirect_port);
1717

18-
let mut session_config = SessionConfig::default();
18+
let mut session_config = SessionConfig::new();
1919
if let Some(warehouse) = warehouse {
2020
session_config = session_config.with_warehouse(warehouse);
2121
}

examples/statement_bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async fn build_session() -> std::result::Result<Session, Box<dyn std::error::Err
145145
let database = env::var("SNOWFLAKE_DATABASE").ok();
146146
let schema = env::var("SNOWFLAKE_SCHEMA").ok();
147147

148-
let mut session_config = SessionConfig::default();
148+
let mut session_config = SessionConfig::new();
149149
if let Some(value) = warehouse {
150150
session_config = session_config.with_warehouse(value);
151151
}

src/auth/external_browser/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ impl Default for ExternalBrowserConfig {
116116
impl ExternalBrowserConfig {
117117
/// Creates a callback-listener external-browser configuration.
118118
///
119-
/// This mode starts a local HTTP listener and receives the token automatically
120-
/// from the redirected callback URL.
119+
/// This mode starts a local HTTP listener and receives the token automatically from the redirected callback URL.
121120
///
122121
/// - `browser_launch_mode`: controls whether the auth URL is opened automatically (`Auto`) or only printed for manual open (`Manual`).
123122
/// - `callback_socket_addr`: bind address for the local callback listener (for example `127.0.0.1` or `0.0.0.0`).

src/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl ClientConfig {
161161
}
162162

163163
impl SessionConfig {
164+
pub fn new() -> Self {
165+
Self::default()
166+
}
167+
164168
pub fn with_warehouse(mut self, warehouse: impl Into<String>) -> Self {
165169
self.warehouse = Some(warehouse.into());
166170
self
@@ -200,6 +204,10 @@ impl SessionConfig {
200204
}
201205

202206
impl QueryConfig {
207+
pub fn new() -> Self {
208+
Self::default()
209+
}
210+
203211
/// Sets the client-side timeout for obtaining a query response from Snowflake.
204212
///
205213
/// This bounds how long [`Session::query()`](crate::Session::query) /
@@ -394,6 +402,10 @@ fn validate_custom_base_url(mut url: Url) -> Result<Url> {
394402
}
395403

396404
impl TransportConfig {
405+
pub fn new() -> Self {
406+
Self::default()
407+
}
408+
397409
pub fn with_proxy(mut self, proxy: ProxyConfig) -> Self {
398410
self.proxy = Some(proxy);
399411
self

src/result_cursor/collect.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ use crate::{
1111
use super::{model::ResultSnapshot, remote::PartitionSource};
1212

1313
/// Options for controlling how result-set collection fetches remaining partitions.
14-
#[derive(Clone, Debug)]
14+
#[derive(Clone, Debug, Default)]
1515
pub struct CollectOptions {
1616
pub(crate) prefetch_concurrency: Option<NonZeroUsize>,
1717
}
1818

1919
impl CollectOptions {
2020
pub fn new() -> Self {
21-
Self {
22-
prefetch_concurrency: None,
23-
}
21+
Self::default()
2422
}
2523

2624
/// Overrides the connection's default prefetch concurrency for this collect call.
@@ -30,12 +28,6 @@ impl CollectOptions {
3028
}
3129
}
3230

33-
impl Default for CollectOptions {
34-
fn default() -> Self {
35-
Self::new()
36-
}
37-
}
38-
3931
#[derive(Clone, Copy)]
4032
pub(crate) struct CollectPolicy {
4133
pub(crate) prefetch_concurrency: NonZeroUsize,

0 commit comments

Comments
 (0)