blob: f65dc920d03c8347d1fa00835bf3df6d8a192d1f [file] [log] [blame] [edit]
// generated by diplomat-tool
part of 'lib.g.dart';
/// An ICU4X TimeFormatter object capable of formatting an [`Time`] type (and others) as a string
///
/// See the [Rust documentation for `TimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html) for more information.
final class TimeFormatter 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.
TimeFormatter._fromFfi(this._ffi, this._selfEdge) {
if (_selfEdge.isEmpty) {
_finalizer.attach(this, _ffi.cast());
}
}
static final _finalizer =
ffi.NativeFinalizer(ffi.Native.addressOf(_ICU4XTimeFormatter_destroy));
/// Creates a new [`TimeFormatter`] from locale data.
///
/// See the [Rust documentation for `try_new_with_length`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.try_new_with_length) for more information.
///
/// Throws [Error] on failure.
factory TimeFormatter.withLength(
DataProvider provider, Locale locale, TimeLength length) {
final result = _ICU4XTimeFormatter_create_with_length(
provider._ffi, locale._ffi, length.index);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return TimeFormatter._fromFfi(result.union.ok, []);
}
/// Formats a [`Time`] to a string.
///
/// See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information.
///
/// Throws [Error] on failure.
String formatTime(Time value) {
final writeable = _Writeable();
final result =
_ICU4XTimeFormatter_format_time(_ffi, value._ffi, writeable._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
/// Formats a [`DateTime`] to a string.
///
/// See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information.
///
/// Throws [Error] on failure.
String formatDatetime(DateTime value) {
final writeable = _Writeable();
final result =
_ICU4XTimeFormatter_format_datetime(_ffi, value._ffi, writeable._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
/// Formats a [`IsoDateTime`] to a string.
///
/// See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information.
///
/// Throws [Error] on failure.
String formatIsoDatetime(IsoDateTime value) {
final writeable = _Writeable();
final result = _ICU4XTimeFormatter_format_iso_datetime(
_ffi, value._ffi, writeable._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
}
@meta.ResourceIdentifier('ICU4XTimeFormatter_destroy')
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
isLeaf: true, symbol: 'ICU4XTimeFormatter_destroy')
// ignore: non_constant_identifier_names
external void _ICU4XTimeFormatter_destroy(ffi.Pointer<ffi.Void> self);
@meta.ResourceIdentifier('ICU4XTimeFormatter_create_with_length')
@ffi.Native<
_ResultOpaqueInt32 Function(
ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>, ffi.Int32)>(
isLeaf: true, symbol: 'ICU4XTimeFormatter_create_with_length')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _ICU4XTimeFormatter_create_with_length(
ffi.Pointer<ffi.Opaque> provider,
ffi.Pointer<ffi.Opaque> locale,
int length);
@meta.ResourceIdentifier('ICU4XTimeFormatter_format_time')
@ffi.Native<
_ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>,
ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XTimeFormatter_format_time')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XTimeFormatter_format_time(
ffi.Pointer<ffi.Opaque> self,
ffi.Pointer<ffi.Opaque> value,
ffi.Pointer<ffi.Opaque> writeable);
@meta.ResourceIdentifier('ICU4XTimeFormatter_format_datetime')
@ffi.Native<
_ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>,
ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XTimeFormatter_format_datetime')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XTimeFormatter_format_datetime(
ffi.Pointer<ffi.Opaque> self,
ffi.Pointer<ffi.Opaque> value,
ffi.Pointer<ffi.Opaque> writeable);
@meta.ResourceIdentifier('ICU4XTimeFormatter_format_iso_datetime')
@ffi.Native<
_ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>,
ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XTimeFormatter_format_iso_datetime')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XTimeFormatter_format_iso_datetime(
ffi.Pointer<ffi.Opaque> self,
ffi.Pointer<ffi.Opaque> value,
ffi.Pointer<ffi.Opaque> writeable);