blob: 9d367631407635007699d61743b50005e02fd0c6 [file]
// generated by diplomat-tool
// dart format off
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 `WeekInformation`](https://docs.rs/icu/2.0.0/icu/calendar/week/struct.WeekInformation.html) for more information.
final class WeekInformation 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.
WeekInformation._fromFfi(this._ffi, this._selfEdge) {
if (_selfEdge.isEmpty) {
_finalizer.attach(this, _ffi.cast());
}
}
@_DiplomatFfiUse('icu4x_WeekInformation_destroy_mv1')
static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_WeekInformation_destroy_mv1));
/// Creates a new [WeekInformation] from locale data using compiled data.
///
/// See the [Rust documentation for `try_new`](https://docs.rs/icu/2.0.0/icu/calendar/week/struct.WeekInformation.html#method.try_new) for more information.
///
/// Throws [DataError] on failure.
factory WeekInformation(Locale locale) {
final result = _icu4x_WeekInformation_create_mv1(locale._ffi);
if (!result.isOk) {
throw DataError.values[result.union.err];
}
return WeekInformation._fromFfi(result.union.ok, []);
}
/// Creates a new [WeekInformation] from locale data using a particular data source.
///
/// See the [Rust documentation for `try_new`](https://docs.rs/icu/2.0.0/icu/calendar/week/struct.WeekInformation.html#method.try_new) for more information.
///
/// Throws [DataError] on failure.
factory WeekInformation.withProvider(DataProvider provider, Locale locale) {
final result = _icu4x_WeekInformation_create_with_provider_mv1(provider._ffi, locale._ffi);
if (!result.isOk) {
throw DataError.values[result.union.err];
}
return WeekInformation._fromFfi(result.union.ok, []);
}
/// Returns the weekday that starts the week for this object's locale
///
/// See the [Rust documentation for `first_weekday`](https://docs.rs/icu/2.0.0/icu/calendar/week/struct.WeekInformation.html#structfield.first_weekday) for more information.
Weekday get firstWeekday {
final result = _icu4x_WeekInformation_first_weekday_mv1(_ffi);
return Weekday.values.firstWhere((v) => v._ffi == result);
}
/// See the [Rust documentation for `weekend`](https://docs.rs/icu/2.0.0/icu/calendar/week/struct.WeekInformation.html#structfield.weekend) for more information.
///
/// See the [Rust documentation for `contains`](https://docs.rs/icu/2.0.0/icu/calendar/provider/struct.WeekdaySet.html#method.contains) for more information.
bool isWeekend(Weekday day) {
final result = _icu4x_WeekInformation_is_weekend_mv1(_ffi, day._ffi);
return result;
}
/// See the [Rust documentation for `weekend`](https://docs.rs/icu/2.0.0/icu/calendar/week/struct.WeekInformation.html#method.weekend) for more information.
WeekdaySetIterator get weekend {
final result = _icu4x_WeekInformation_weekend_mv1(_ffi);
return WeekdaySetIterator._fromFfi(result, []);
}
}
@_DiplomatFfiUse('icu4x_WeekInformation_destroy_mv1')
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(isLeaf: true, symbol: 'icu4x_WeekInformation_destroy_mv1')
// ignore: non_constant_identifier_names
external void _icu4x_WeekInformation_destroy_mv1(ffi.Pointer<ffi.Void> self);
@_DiplomatFfiUse('icu4x_WeekInformation_create_mv1')
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WeekInformation_create_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WeekInformation_create_mv1(ffi.Pointer<ffi.Opaque> locale);
@_DiplomatFfiUse('icu4x_WeekInformation_create_with_provider_mv1')
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WeekInformation_create_with_provider_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WeekInformation_create_with_provider_mv1(ffi.Pointer<ffi.Opaque> provider, ffi.Pointer<ffi.Opaque> locale);
@_DiplomatFfiUse('icu4x_WeekInformation_first_weekday_mv1')
@ffi.Native<ffi.Int32 Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WeekInformation_first_weekday_mv1')
// ignore: non_constant_identifier_names
external int _icu4x_WeekInformation_first_weekday_mv1(ffi.Pointer<ffi.Opaque> self);
@_DiplomatFfiUse('icu4x_WeekInformation_is_weekend_mv1')
@ffi.Native<ffi.Bool Function(ffi.Pointer<ffi.Opaque>, ffi.Int32)>(isLeaf: true, symbol: 'icu4x_WeekInformation_is_weekend_mv1')
// ignore: non_constant_identifier_names
external bool _icu4x_WeekInformation_is_weekend_mv1(ffi.Pointer<ffi.Opaque> self, int day);
@_DiplomatFfiUse('icu4x_WeekInformation_weekend_mv1')
@ffi.Native<ffi.Pointer<ffi.Opaque> Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WeekInformation_weekend_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_WeekInformation_weekend_mv1(ffi.Pointer<ffi.Opaque> self);
// dart format on