Skip to content

Commit

Permalink
More by-copy methods for Borrowed types
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 10, 2025
1 parent be20a61 commit d7c2fd6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'data> PatternBorrowed<'data> {
metadata: PatternMetadata::DEFAULT,
};

pub(crate) fn as_pattern(&self) -> Pattern<'data> {
pub(crate) fn as_pattern(self) -> Pattern<'data> {
Pattern {
items: self.items.as_zerovec(),
metadata: self.metadata,
Expand Down
2 changes: 1 addition & 1 deletion components/normalizer/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl CanonicalCompositionBorrowed<'_> {
/// assert_eq!(comp.compose('가', 'ᆨ'), Some('각')); // Hangul LVT
/// ```
#[inline(always)]
pub fn compose(&self, starter: char, second: char) -> Option<char> {
pub fn compose(self, starter: char, second: char) -> Option<char> {
crate::compose(
self.canonical_compositions.canonical_compositions.iter(),
starter,
Expand Down
2 changes: 1 addition & 1 deletion components/properties/src/code_point_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<'a, T: TrieValue> CodePointMapDataBorrowed<'a, T> {

impl CodePointMapDataBorrowed<'_, GeneralCategory> {
/// TODO
pub fn get_set_for_value_group(&self, value: GeneralCategoryGroup) -> crate::CodePointSetData {
pub fn get_set_for_value_group(self, value: GeneralCategoryGroup) -> crate::CodePointSetData {
let matching_gc_ranges = self
.iter_ranges()
.filter(|cpm_range| (1 << cpm_range.value as u32) & value.0 != 0)
Expand Down
4 changes: 2 additions & 2 deletions components/properties/src/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ impl EmojiSetDataBorrowed<'_> {

/// Check if the set contains the code point.
#[inline]
pub fn contains(&self, ch: char) -> bool {
pub fn contains(self, ch: char) -> bool {
self.set.contains(ch)
}

/// See [`Self::contains`].
#[inline]
pub fn contains32(&self, cp: u32) -> bool {
pub fn contains32(self, cp: u32) -> bool {
self.set.contains32(cp)
}
}
Expand Down
14 changes: 7 additions & 7 deletions components/properties/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
/// assert_eq!(lookup.get_strict_u16("UppercaseLetter"), None);
/// ```
#[inline]
pub fn get_strict_u16(&self, name: &str) -> Option<u16> {
pub fn get_strict_u16(self, name: &str) -> Option<u16> {
get_strict_u16(self.map, name)
}

Expand All @@ -176,7 +176,7 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
/// assert_eq!(lookup.get_strict("UppercaseLetter"), None);
/// ```
#[inline]
pub fn get_strict(&self, name: &str) -> Option<T> {
pub fn get_strict(self, name: &str) -> Option<T> {
T::try_from_u32(self.get_strict_u16(name)? as u32).ok()
}

Expand Down Expand Up @@ -206,7 +206,7 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
/// );
/// ```
#[inline]
pub fn get_loose_u16(&self, name: &str) -> Option<u16> {
pub fn get_loose_u16(self, name: &str) -> Option<u16> {
get_loose_u16(self.map, name)
}

Expand Down Expand Up @@ -236,7 +236,7 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
/// );
/// ```
#[inline]
pub fn get_loose(&self, name: &str) -> Option<T> {
pub fn get_loose(self, name: &str) -> Option<T> {
T::try_from_u32(self.get_loose_u16(name)? as u32).ok()
}
}
Expand Down Expand Up @@ -431,7 +431,7 @@ impl<T: NamedEnumeratedProperty> PropertyNamesLongBorrowed<'_, T> {
/// );
/// ```
#[inline]
pub fn get(&self, property: T) -> Option<&str> {
pub fn get(self, property: T) -> Option<&str> {
self.map.get(property.to_u32())
}
}
Expand Down Expand Up @@ -558,7 +558,7 @@ impl<T: NamedEnumeratedProperty> PropertyNamesShortBorrowed<'_, T> {
/// assert_eq!(lookup.get(CanonicalCombiningClass::AboveLeft), Some("AL"));
/// ```
#[inline]
pub fn get(&self, property: T) -> Option<&str> {
pub fn get(self, property: T) -> Option<&str> {
self.map.get(property.to_u32())
}
}
Expand Down Expand Up @@ -603,7 +603,7 @@ impl PropertyNamesShortBorrowed<'_, Script> {
/// );
/// ```
#[inline]
pub fn get_locale_script(&self, property: Script) -> Option<icu_locale_core::subtags::Script> {
pub fn get_locale_script(self, property: Script) -> Option<icu_locale_core::subtags::Script> {
let prop = usize::try_from(property.to_u32()).ok()?;
self.map.map.get(prop).and_then(|o| o.0)
}
Expand Down
2 changes: 1 addition & 1 deletion components/timezone/src/windows_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl WindowsTimeZoneMapperBorrowed<'_> {
/// assert_eq!(bcp47_id, Some(TimeZoneBcp47Id(tinystr!(8, "cawnp"))));
/// ```
pub fn windows_tz_to_bcp47_id(
&self,
self,
windows_tz: &str,
region: Option<Region>,
) -> Option<TimeZoneBcp47Id> {
Expand Down
4 changes: 2 additions & 2 deletions provider/core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ impl<'a> DataIdentifierBorrowed<'a> {
}

/// Converts this [`DataIdentifierBorrowed`] into a [`DataIdentifierCow<'static>`].
pub fn into_owned(&self) -> DataIdentifierCow<'static> {
pub fn into_owned(self) -> DataIdentifierCow<'static> {
DataIdentifierCow {
marker_attributes: Cow::Owned(self.marker_attributes.to_owned()),
locale: Cow::Owned(self.locale.clone()),
}
}

/// Borrows this [`DataIdentifierBorrowed`] as a [`DataIdentifierCow<'a>`].
pub fn as_cow(&self) -> DataIdentifierCow<'a> {
pub fn as_cow(self) -> DataIdentifierCow<'a> {
DataIdentifierCow {
marker_attributes: Cow::Borrowed(self.marker_attributes),
locale: Cow::Borrowed(self.locale),
Expand Down

0 comments on commit d7c2fd6

Please sign in to comment.