blob: 7c1f2f12b3652750ee0e065411dd6bdcc0efd25c [file] [log] [blame] [edit]
// generated by diplomat-tool
part of 'lib.g.dart';
/// A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types
///
/// See the [Rust documentation for `WeekCalculator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html) for more information.
final class WeekCalculator implements ffi.Finalizable {
final ffi.Pointer<ffi.Opaque> _ffi;
// These are "used" in the sense that they keep dependencies alive
// ignore: unused_field
final core.List<Object> _selfEdge;
// This takes in a list of lifetime edges (including for &self borrows)
// corresponding to data this may borrow from. These should be flat arrays containing
// references to objects, and this object will hold on to them to keep them alive and
// maintain borrow validity.
WeekCalculator._fromFfi(this._ffi, this._selfEdge) {
if (_selfEdge.isEmpty) {
_finalizer.attach(this, _ffi.cast());
}
}
static final _finalizer =
ffi.NativeFinalizer(ffi.Native.addressOf(_ICU4XWeekCalculator_destroy));
/// Creates a new [`WeekCalculator`] from locale data.
///
/// See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.try_new) for more information.
///
/// Throws [Error] on failure.
factory WeekCalculator(DataProvider provider, Locale locale) {
final result = _ICU4XWeekCalculator_create(provider._ffi, locale._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return WeekCalculator._fromFfi(result.union.ok, []);
}
/// Additional information: [1](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday), [2](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days)
factory WeekCalculator.fromFirstDayOfWeekAndMinWeekDays(
IsoWeekday firstWeekday, int minWeekDays) {
final result =
_ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(
firstWeekday._ffi, minWeekDays);
return WeekCalculator._fromFfi(result, []);
}
/// Returns the weekday that starts the week for this object's locale
///
/// See the [Rust documentation for `first_weekday`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday) for more information.
IsoWeekday get firstWeekday {
final result = _ICU4XWeekCalculator_first_weekday(_ffi);
return IsoWeekday.values.firstWhere((v) => v._ffi == result);
}
/// The minimum number of days overlapping a year required for a week to be
/// considered part of that year
///
/// See the [Rust documentation for `min_week_days`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days) for more information.
int get minWeekDays {
final result = _ICU4XWeekCalculator_min_week_days(_ffi);
return result;
}
/// See the [Rust documentation for `weekend`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.weekend) for more information.
WeekendContainsDay get weekend {
final result = _ICU4XWeekCalculator_weekend(_ffi);
return WeekendContainsDay._fromFfi(result);
}
}
@meta.ResourceIdentifier('ICU4XWeekCalculator_destroy')
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
isLeaf: true, symbol: 'ICU4XWeekCalculator_destroy')
// ignore: non_constant_identifier_names
external void _ICU4XWeekCalculator_destroy(ffi.Pointer<ffi.Void> self);
@meta.ResourceIdentifier('ICU4XWeekCalculator_create')
@ffi.Native<
_ResultOpaqueInt32 Function(
ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XWeekCalculator_create')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _ICU4XWeekCalculator_create(
ffi.Pointer<ffi.Opaque> provider, ffi.Pointer<ffi.Opaque> locale);
@meta.ResourceIdentifier(
'ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days')
@ffi.Native<ffi.Pointer<ffi.Opaque> Function(ffi.Int32, ffi.Uint8)>(
isLeaf: true,
symbol:
'ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque>
_ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(
int firstWeekday, int minWeekDays);
@meta.ResourceIdentifier('ICU4XWeekCalculator_first_weekday')
@ffi.Native<ffi.Int32 Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XWeekCalculator_first_weekday')
// ignore: non_constant_identifier_names
external int _ICU4XWeekCalculator_first_weekday(ffi.Pointer<ffi.Opaque> self);
@meta.ResourceIdentifier('ICU4XWeekCalculator_min_week_days')
@ffi.Native<ffi.Uint8 Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XWeekCalculator_min_week_days')
// ignore: non_constant_identifier_names
external int _ICU4XWeekCalculator_min_week_days(ffi.Pointer<ffi.Opaque> self);
@meta.ResourceIdentifier('ICU4XWeekCalculator_weekend')
@ffi.Native<_WeekendContainsDayFfi Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XWeekCalculator_weekend')
// ignore: non_constant_identifier_names
external _WeekendContainsDayFfi _ICU4XWeekCalculator_weekend(
ffi.Pointer<ffi.Opaque> self);