Skip to content

Commit ca86ec6

Browse files
committed
copy
1 parent be1630b commit ca86ec6

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

components/calendar/src/any_calendar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ macro_rules! make_any_calendar {
4545
)*
4646
) => {
4747
$(#[$any_calendar_meta])*
48-
#[derive(Debug, Clone)]
48+
#[derive(Debug, Clone, Copy)]
4949
// TODO(#3469): Decide on the best way to implement Ord.
5050
pub enum $any_calendar_ident {
5151
$(

components/datetime/src/scaffold/calendar.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ enum FormattableAnyCalendarKind {
311311
}
312312

313313
impl FormattableAnyCalendarKind {
314-
fn try_from_any_calendar(cal: &AnyCalendar) -> Option<Self> {
314+
fn try_from_any_calendar(cal: AnyCalendar) -> Option<Self> {
315315
use AnyCalendarKind::*;
316316
let res = match cal.kind() {
317317
Buddhist => Self::Buddhist,
@@ -371,7 +371,7 @@ fn test_calendar_fallback() {
371371
}
372372

373373
/// A version of [`AnyCalendar`] for the calendars supported in the any-calendar formatter.
374-
#[derive(Debug, Clone, PartialEq)]
374+
#[derive(Debug, Clone, PartialEq, Copy)]
375375
pub(crate) struct FormattableAnyCalendar {
376376
any_calendar: AnyCalendar,
377377
}
@@ -384,7 +384,7 @@ impl FormattableAnyCalendar {
384384
}
385385

386386
pub(crate) fn try_from_any_calendar(any_calendar: AnyCalendar) -> Result<Self, AnyCalendar> {
387-
match FormattableAnyCalendarKind::try_from_any_calendar(&any_calendar) {
387+
match FormattableAnyCalendarKind::try_from_any_calendar(any_calendar) {
388388
Some(_) => Ok(Self { any_calendar }),
389389
None => Err(any_calendar),
390390
}
@@ -394,8 +394,8 @@ impl FormattableAnyCalendar {
394394
&self.any_calendar
395395
}
396396

397-
fn kind(&self) -> FormattableAnyCalendarKind {
398-
FormattableAnyCalendarKind::try_from_any_calendar(&self.any_calendar).unwrap_or_else(|| {
397+
fn kind(self) -> FormattableAnyCalendarKind {
398+
FormattableAnyCalendarKind::try_from_any_calendar(self.any_calendar).unwrap_or_else(|| {
399399
debug_assert!(false, "unreachable by invariant");
400400
// fall back to something non-Gregorian to make errors more obvious
401401
FormattableAnyCalendarKind::Coptic

ffi/capi/src/date.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub mod ffi {
7474
#[diplomat::rust_link(icu::calendar::Date::to_calendar, FnInStruct)]
7575
#[diplomat::attr(demo_gen, disable)] // covered by Date
7676
pub fn to_calendar(&self, calendar: &Calendar) -> Box<Date> {
77-
Box::new(Date(self.0.to_calendar(calendar.0.clone())))
77+
Box::new(Date(self.0.to_calendar(calendar.0)))
7878
}
7979

8080
#[diplomat::rust_link(icu::calendar::Date::to_any, FnInStruct)]
@@ -247,9 +247,9 @@ pub mod ffi {
247247
iso_day: u8,
248248
calendar: &Calendar,
249249
) -> Result<Box<Date>, CalendarError> {
250-
let cal = calendar.0.clone();
251250
Ok(Box::new(Date(
252-
icu_calendar::Date::try_new_iso(iso_year, iso_month, iso_day)?.to_calendar(cal),
251+
icu_calendar::Date::try_new_iso(iso_year, iso_month, iso_day)?
252+
.to_calendar(calendar.0),
253253
)))
254254
}
255255

@@ -265,11 +265,10 @@ pub mod ffi {
265265
options: DateFromFieldsOptions,
266266
calendar: &Calendar,
267267
) -> Result<Box<Date>, CalendarDateFromFieldsError> {
268-
let cal = calendar.0.clone();
269268
Ok(Box::new(Date(icu_calendar::Date::try_from_fields(
270269
fields.into(),
271270
options.into(),
272-
cal,
271+
calendar.0,
273272
)?)))
274273
}
275274

@@ -293,9 +292,8 @@ pub mod ffi {
293292
None
294293
};
295294
let month = icu_calendar::types::Month::try_from_utf8(month_code)?.code();
296-
let cal = calendar.0.clone();
297295
Ok(Box::new(Date(icu_calendar::Date::try_new_from_codes(
298-
era, year, month, day, cal,
296+
era, year, month, day, calendar.0,
299297
)?)))
300298
}
301299

@@ -304,10 +302,9 @@ pub mod ffi {
304302
#[diplomat::attr(all(supports = named_constructors), named_constructor)]
305303
#[diplomat::demo(default_constructor)]
306304
pub fn from_rata_die(rd: i64, calendar: &Calendar) -> Result<Box<Date>, CalendarError> {
307-
let cal = calendar.0.clone();
308305
Ok(Box::new(Date(icu_calendar::Date::from_rata_die(
309306
icu_calendar::types::RataDie::new(rd),
310-
cal,
307+
calendar.0,
311308
))))
312309
}
313310

@@ -321,16 +318,15 @@ pub mod ffi {
321318
calendar: &Calendar,
322319
) -> Result<Box<Date>, Rfc9557ParseError> {
323320
Ok(Box::new(Date(icu_calendar::Date::try_from_utf8(
324-
v,
325-
calendar.0.clone(),
321+
v, calendar.0,
326322
)?)))
327323
}
328324

329325
/// Convert this date to one in a different calendar
330326
#[diplomat::rust_link(icu::calendar::Date::to_calendar, FnInStruct)]
331327
#[diplomat::rust_link(icu::calendar::Date::convert_any, FnInStruct, hidden)]
332328
pub fn to_calendar(&self, calendar: &Calendar) -> Box<Date> {
333-
Box::new(Date(self.0.to_calendar(calendar.0.clone())))
329+
Box::new(Date(self.0.to_calendar(calendar.0)))
334330
}
335331

336332
/// Converts this date to ISO
@@ -501,7 +497,7 @@ pub mod ffi {
501497
#[diplomat::rust_link(icu::calendar::Date::calendar_wrapper, FnInStruct, hidden)]
502498
#[diplomat::attr(auto, getter)]
503499
pub fn calendar(&self) -> Box<Calendar> {
504-
Box::new(Calendar(self.0.calendar().clone()))
500+
Box::new(Calendar(*self.0.calendar()))
505501
}
506502
}
507503

ffi/capi/src/datetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub mod ffi {
5555
calendar: &Calendar,
5656
) -> Result<DateTime, Rfc9557ParseError> {
5757
let icu_time::DateTime { date, time } =
58-
icu_time::DateTime::try_from_utf8(v, calendar.0.clone())?;
58+
icu_time::DateTime::try_from_utf8(v, calendar.0)?;
5959
Ok(DateTime {
6060
date: Box::new(Date(date)),
6161
time: Box::new(Time(time)),

ffi/capi/src/zoned_datetime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub mod ffi {
104104
let icu_time::ZonedDateTime { date, time, zone } =
105105
icu_time::ZonedDateTime::try_strict_from_utf8(
106106
v,
107-
calendar.0.clone(),
107+
calendar.0,
108108
iana_parser.0.as_borrowed(),
109109
)?;
110110
Ok(ZonedDateTime {
@@ -146,7 +146,7 @@ pub mod ffi {
146146
let icu_time::ZonedDateTime { date, time, zone } =
147147
icu_time::ZonedDateTime::try_location_only_from_utf8(
148148
v,
149-
calendar.0.clone(),
149+
calendar.0,
150150
iana_parser.0.as_borrowed(),
151151
)?;
152152
Ok(ZonedDateTime {
@@ -169,7 +169,7 @@ pub mod ffi {
169169
calendar: &Calendar,
170170
) -> Result<ZonedDateTime, Rfc9557ParseError> {
171171
let icu_time::ZonedDateTime { date, time, zone } =
172-
icu_time::ZonedDateTime::try_offset_only_from_utf8(v, calendar.0.clone())?;
172+
icu_time::ZonedDateTime::try_offset_only_from_utf8(v, calendar.0)?;
173173
Ok(ZonedDateTime {
174174
date: Box::new(Date(date)),
175175
time: Box::new(Time(time)),
@@ -189,7 +189,7 @@ pub mod ffi {
189189
let icu_time::ZonedDateTime { date, time, zone } =
190190
icu_time::ZonedDateTime::try_lenient_from_utf8(
191191
v,
192-
calendar.0.clone(),
192+
calendar.0,
193193
iana_parser.0.as_borrowed(),
194194
)?;
195195
Ok(ZonedDateTime {

0 commit comments

Comments
 (0)