Skip to content

Commit 945e1b6

Browse files
committed
feat: change into_key to cloned_key which explicitly clones Arcs
1 parent e7fe343 commit 945e1b6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,16 @@ impl<Identifier> Array<Identifier> {
619619
(ty, is_var)
620620
}
621621

622-
/// Converts an array reference into an [`ArcKey`].
622+
/// Clones this array reference into an [`ArcKey`].
623623
///
624624
/// This is useful when storing arrays in collections such as
625625
/// [`HashMap`](std::collections::HashMap), [`HashSet`], and
626626
/// [`BTreeMap`](std::collections::BTreeMap), where the key should identify
627627
/// the specific parsed array object rather than its contents or `name`.
628628
///
629+
/// This method clones the [`Arc`] reference count and keeps the original
630+
/// array reference usable by the caller.
631+
///
629632
/// The resulting key uses the allocation / pointer identity of this
630633
/// [`Arc`]. Two arrays with the same name and equal contents will
631634
/// therefore compare as different keys if they are stored in different
@@ -635,8 +638,8 @@ impl<Identifier> Array<Identifier> {
635638
/// identical top-level arrays are allocated only once. In those cases,
636639
/// `ArcKey` is a good fit for keying collections by the canonical parsed
637640
/// array object.
638-
pub fn into_key(self: Arc<Self>) -> ArcKey<Self> {
639-
ArcKey::new(self)
641+
pub fn cloned_key(self: &Arc<Self>) -> ArcKey<Self> {
642+
ArcKey::new(Arc::clone(self))
640643
}
641644
}
642645

@@ -909,13 +912,16 @@ impl Display for Type {
909912
}
910913

911914
impl<Identifier> Variable<Identifier> {
912-
/// Converts a variable reference into an [`ArcKey`].
915+
/// Clones this variable reference into an [`ArcKey`].
913916
///
914917
/// This is useful when storing variables in collections such as
915918
/// [`HashMap`](std::collections::HashMap), [`HashSet`], and
916919
/// [`BTreeMap`](std::collections::BTreeMap), where the key should identify
917920
/// the specific parsed variable object rather than its fields or `name`.
918921
///
922+
/// This method clones the [`Arc`] reference count and keeps the original
923+
/// variable reference usable by the caller.
924+
///
919925
/// The resulting key uses the allocation / pointer identity of this
920926
/// [`Arc`]. Two variables with the same name and equal fields will
921927
/// therefore compare as different keys if they are stored in different
@@ -925,7 +931,7 @@ impl<Identifier> Variable<Identifier> {
925931
/// identical top-level variables are allocated only once. In those cases,
926932
/// `ArcKey` is a good fit for keying collections by the canonical parsed
927933
/// variable object.
928-
pub fn into_key(self: Arc<Self>) -> ArcKey<Self> {
929-
ArcKey::new(self)
934+
pub fn cloned_key(self: &Arc<Self>) -> ArcKey<Self> {
935+
ArcKey::new(Arc::clone(self))
930936
}
931937
}

0 commit comments

Comments
 (0)