Skip to content

Commit 80bab06

Browse files
RUST-2097 Migrate from derivative to derive-where (#1245)
1 parent 3df0eab commit 80bab06

File tree

14 files changed

+64
-65
lines changed

14 files changed

+64
-65
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ chrono = { version = "0.4.7", default-features = false, features = [
7676
"clock",
7777
"std",
7878
] }
79-
derivative = "2.1.1"
8079
derive_more = "0.99.17"
80+
derive-where = "1.2.7"
8181
flate2 = { version = "1.0", optional = true }
8282
futures-io = "0.3.21"
8383
futures-core = "0.3.14"

src/change_stream.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
#[cfg(test)]
1515
use bson::RawDocumentBuf;
1616
use bson::{Document, Timestamp};
17-
use derivative::Derivative;
17+
use derive_where::derive_where;
1818
use futures_core::{future::BoxFuture, Stream};
1919
use serde::de::DeserializeOwned;
2020
#[cfg(test)]
@@ -74,8 +74,7 @@ use crate::{
7474
///
7575
/// See the documentation [here](https://www.mongodb.com/docs/manual/changeStreams) for more
7676
/// details. Also see the documentation on [usage recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/).
77-
#[derive(Derivative)]
78-
#[derivative(Debug)]
77+
#[derive_where(Debug)]
7978
pub struct ChangeStream<T>
8079
where
8180
T: DeserializeOwned,
@@ -90,7 +89,7 @@ where
9089
data: ChangeStreamData,
9190

9291
/// A pending future for a resume.
93-
#[derivative(Debug = "ignore")]
92+
#[derive_where(skip)]
9493
pending_resume: Option<BoxFuture<'static, Result<ChangeStream<T>>>>,
9594
}
9695

src/client.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616

1717
#[cfg(feature = "in-use-encryption")]
1818
pub use self::csfle::client_builder::*;
19-
use derivative::Derivative;
19+
use derive_where::derive_where;
2020
use futures_core::Future;
2121
use futures_util::FutureExt;
2222

@@ -124,8 +124,7 @@ const _: fn() = || {
124124
assert_sync(_c);
125125
};
126126

127-
#[derive(Derivative)]
128-
#[derivative(Debug)]
127+
#[derive(Debug)]
129128
struct ClientInner {
130129
topology: Topology,
131130
options: ClientOptions,
@@ -648,10 +647,9 @@ impl WeakClient {
648647
}
649648
}
650649

651-
#[derive(Derivative)]
652-
#[derivative(Debug)]
650+
#[derive_where(Debug)]
653651
pub(crate) struct AsyncDropToken {
654-
#[derivative(Debug = "ignore")]
652+
#[derive_where(skip)]
655653
tx: Option<tokio::sync::oneshot::Sender<BoxFuture<'static, ()>>>,
656654
}
657655

src/client/auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod x509;
1515
use std::{borrow::Cow, fmt::Debug, str::FromStr};
1616

1717
use bson::RawDocumentBuf;
18-
use derivative::Derivative;
18+
use derive_where::derive_where;
1919
use hmac::{digest::KeyInit, Mac};
2020
use rand::Rng;
2121
use serde::Deserialize;
@@ -458,8 +458,8 @@ impl FromStr for AuthMechanism {
458458
///
459459
/// Some fields (mechanism and source) may be omitted and will either be negotiated or assigned a
460460
/// default value, depending on the values of other fields in the credential.
461-
#[derive(Clone, Default, Deserialize, TypedBuilder, Derivative)]
462-
#[derivative(PartialEq)]
461+
#[derive(Clone, Default, Deserialize, TypedBuilder)]
462+
#[derive_where(PartialEq)]
463463
#[builder(field_defaults(default, setter(into)))]
464464
#[non_exhaustive]
465465
pub struct Credential {
@@ -506,7 +506,7 @@ pub struct Credential {
506506
/// }
507507
/// ```
508508
#[serde(skip)]
509-
#[derivative(Debug = "ignore", PartialEq = "ignore")]
509+
#[derive_where(skip)]
510510
#[builder(default)]
511511
pub oidc_callback: oidc::Callback,
512512
}

src/client/csfle.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub(crate) mod state_machine;
55

66
use std::{path::Path, time::Duration};
77

8-
use derivative::Derivative;
8+
use derive_where::derive_where;
99
use mongocrypt::Crypt;
1010

1111
use crate::{
@@ -28,13 +28,12 @@ use self::state_machine::{CryptExecutor, MongocryptdOptions};
2828

2929
use super::WeakClient;
3030

31-
#[derive(Derivative)]
32-
#[derivative(Debug)]
31+
#[derive_where(Debug)]
3332
pub(super) struct ClientState {
34-
#[derivative(Debug = "ignore")]
33+
#[derive_where(skip)]
3534
crypt: Crypt,
3635
exec: CryptExecutor,
37-
internal_client: Option<Client>,
36+
_internal_client: Option<Client>,
3837
opts: AutoEncryptionOptions,
3938
}
4039

@@ -79,7 +78,7 @@ impl ClientState {
7978
Ok(Self {
8079
crypt,
8180
exec,
82-
internal_client: aux_clients.internal_client,
81+
_internal_client: aux_clients.internal_client,
8382
opts,
8483
})
8584
}

src/client/options.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{
1818
};
1919

2020
use bson::UuidRepresentation;
21-
use derivative::Derivative;
21+
use derive_where::derive_where;
2222
use once_cell::sync::Lazy;
2323
use serde::{de::Unexpected, Deserialize, Deserializer, Serialize};
2424
use serde_with::skip_serializing_none;
@@ -391,9 +391,9 @@ pub struct ServerApi {
391391
}
392392

393393
/// Contains the options that can be used to create a new [`Client`](../struct.Client.html).
394-
#[derive(Clone, Derivative, Deserialize, TypedBuilder)]
394+
#[derive(Clone, Deserialize, TypedBuilder)]
395395
#[builder(field_defaults(default, setter(into)))]
396-
#[derivative(Debug, PartialEq)]
396+
#[derive_where(Debug, PartialEq)]
397397
#[serde(rename_all = "camelCase")]
398398
#[non_exhaustive]
399399
pub struct ClientOptions {
@@ -427,15 +427,15 @@ pub struct ClientOptions {
427427
pub compressors: Option<Vec<Compressor>>,
428428

429429
/// The handler that should process all Connection Monitoring and Pooling events.
430-
#[derivative(Debug = "ignore", PartialEq = "ignore")]
430+
#[derive_where(skip)]
431431
#[builder(setter(strip_option))]
432432
#[serde(skip)]
433433
pub cmap_event_handler: Option<EventHandler<crate::event::cmap::CmapEvent>>,
434434

435435
/// The handler that should process all command-related events.
436436
///
437437
/// Note that monitoring command events may incur a performance penalty.
438-
#[derivative(Debug = "ignore", PartialEq = "ignore")]
438+
#[derive_where(skip)]
439439
#[builder(setter(strip_option))]
440440
#[serde(skip)]
441441
pub command_event_handler: Option<EventHandler<crate::event::command::CommandEvent>>,
@@ -531,7 +531,7 @@ pub struct ClientOptions {
531531
pub server_monitoring_mode: Option<ServerMonitoringMode>,
532532

533533
/// The handler that should process all Server Discovery and Monitoring events.
534-
#[derivative(Debug = "ignore", PartialEq = "ignore")]
534+
#[derive_where(skip)]
535535
#[builder(setter(strip_option))]
536536
#[serde(skip)]
537537
pub sdam_event_handler: Option<EventHandler<crate::event::sdam::SdamEvent>>,
@@ -568,7 +568,7 @@ pub struct ClientOptions {
568568
pub srv_service_name: Option<String>,
569569

570570
#[builder(setter(skip))]
571-
#[derivative(Debug = "ignore")]
571+
#[derive_where(skip(Debug))]
572572
pub(crate) socket_timeout: Option<Duration>,
573573

574574
/// The TLS configuration for the Client to use in its connections with the server.
@@ -598,12 +598,12 @@ pub struct ClientOptions {
598598
/// Information from the SRV URI that generated these client options, if applicable.
599599
#[builder(setter(skip))]
600600
#[serde(skip)]
601-
#[derivative(Debug = "ignore")]
601+
#[derive_where(skip(Debug))]
602602
pub(crate) original_srv_info: Option<OriginalSrvInfo>,
603603

604604
#[cfg(test)]
605605
#[builder(setter(skip))]
606-
#[derivative(Debug = "ignore")]
606+
#[derive_where(skip(Debug))]
607607
pub(crate) original_uri: Option<String>,
608608

609609
/// Configuration of the DNS resolver used for SRV and TXT lookups.
@@ -613,15 +613,15 @@ pub struct ClientOptions {
613613
/// system configuration, so a custom configuration is recommended.
614614
#[builder(setter(skip))]
615615
#[serde(skip)]
616-
#[derivative(Debug = "ignore")]
616+
#[derive_where(skip(Debug))]
617617
#[cfg(feature = "dns-resolver")]
618618
pub(crate) resolver_config: Option<ResolverConfig>,
619619

620620
/// Control test behavior of the client.
621621
#[cfg(test)]
622622
#[builder(setter(skip))]
623623
#[serde(skip)]
624-
#[derivative(PartialEq = "ignore")]
624+
#[derive_where(skip)]
625625
pub(crate) test_options: Option<TestOptions>,
626626
}
627627

src/client/session/cluster_time.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use derivative::Derivative;
1+
use derive_where::derive_where;
22
use serde::{Deserialize, Serialize};
33

44
use crate::bson::{Document, Timestamp};
@@ -7,13 +7,13 @@ use crate::bson::{Document, Timestamp};
77
///
88
/// See [the MongoDB documentation](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency/)
99
/// for more information.
10-
#[derive(Debug, Deserialize, Clone, Serialize, Derivative)]
11-
#[derivative(PartialEq, Eq)]
10+
#[derive(Debug, Deserialize, Clone, Serialize)]
11+
#[derive_where(PartialEq, Eq)]
1212
#[serde(rename_all = "camelCase")]
1313
pub struct ClusterTime {
1414
pub(crate) cluster_time: Timestamp,
1515

16-
#[derivative(PartialEq = "ignore")]
16+
#[derive_where(skip)]
1717
pub(crate) signature: Document,
1818
}
1919

src/cmap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod worker;
1111

1212
use std::time::Instant;
1313

14-
use derivative::Derivative;
14+
use derive_where::derive_where;
1515

1616
pub use self::conn::ConnectionInfo;
1717
pub(crate) use self::{
@@ -51,15 +51,15 @@ pub(crate) const DEFAULT_MAX_POOL_SIZE: u32 = 10;
5151
/// A pool of connections implementing the CMAP spec.
5252
/// This type is actually a handle to task that manages the connections and is cheap to clone and
5353
/// pass around.
54-
#[derive(Clone, Derivative)]
55-
#[derivative(Debug)]
54+
#[derive(Clone)]
55+
#[derive_where(Debug)]
5656
pub(crate) struct ConnectionPool {
5757
address: ServerAddress,
5858
manager: PoolManager,
5959
connection_requester: ConnectionRequester,
6060
generation_subscriber: PoolGenerationSubscriber,
6161

62-
#[derivative(Debug = "ignore")]
62+
#[derive_where(skip)]
6363
event_emitter: CmapEventEmitter,
6464
}
6565

src/cmap/conn.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
time::{Duration, Instant},
88
};
99

10-
use derivative::Derivative;
10+
use derive_where::derive_where;
1111
use serde::Serialize;
1212
use tokio::{
1313
io::BufStream,
@@ -59,8 +59,7 @@ pub struct ConnectionInfo {
5959
}
6060

6161
/// A wrapper around Stream that contains all the CMAP information needed to maintain a connection.
62-
#[derive(Derivative)]
63-
#[derivative(Debug)]
62+
#[derive_where(Debug)]
6463
pub(crate) struct Connection {
6564
/// Driver-generated ID for the connection.
6665
pub(crate) id: u32,
@@ -118,11 +117,11 @@ pub(crate) struct Connection {
118117

119118
/// Type responsible for emitting events related to this connection. This is None for
120119
/// monitoring connections as we do not emit events for those.
121-
#[derivative(Debug = "ignore")]
120+
#[derive_where(skip)]
122121
event_emitter: Option<CmapEventEmitter>,
123122

124123
/// The token callback for OIDC authentication.
125-
#[derivative(Debug = "ignore")]
124+
#[derive_where(skip)]
126125
pub(crate) oidc_token_gen_id: tokio::sync::Mutex<u32>,
127126
}
128127

src/cmap/options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::cmp::Ordering;
33
use std::time::Duration;
44

5-
use derivative::Derivative;
5+
use derive_where::derive_where;
66
#[cfg(test)]
77
use serde::de::{Deserializer, Error};
88
use serde::Deserialize;
@@ -18,16 +18,16 @@ use crate::{
1818
};
1919

2020
/// Contains the options for creating a connection pool.
21-
#[derive(Clone, Default, Deserialize, Derivative)]
22-
#[derivative(Debug, PartialEq)]
21+
#[derive(Clone, Default, Deserialize)]
22+
#[derive_where(Debug, PartialEq)]
2323
#[serde(rename_all = "camelCase")]
2424
pub(crate) struct ConnectionPoolOptions {
2525
/// The credential to use for authenticating connections in this pool.
2626
#[serde(skip)]
2727
pub(crate) credential: Option<Credential>,
2828

2929
/// Processes all events generated by the pool.
30-
#[derivative(Debug = "ignore", PartialEq = "ignore")]
30+
#[derive_where(skip)]
3131
#[serde(skip)]
3232
pub(crate) cmap_event_handler: Option<EventHandler<CmapEvent>>,
3333

0 commit comments

Comments
 (0)