blob: 40550aad94df3a2abeee4489bc38958bc714c49e [file] [edit]
// generated by diplomat-tool
part of 'lib.g.dart';
/// An object capable of mapping from an IANA time zone ID to a BCP-47 ID.
///
/// This can be used via `try_set_iana_time_zone_id()` on [`CustomTimeZone`].
///
/// [`CustomTimeZone`]: crate::timezone::ffi::ICU4XCustomTimeZone
///
/// See the [Rust documentation for `IanaToBcp47Mapper`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47Mapper.html) for more information.
final class IanaToBcp47Mapper 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.
IanaToBcp47Mapper._fromFfi(this._ffi, this._selfEdge) {
if (_selfEdge.isEmpty) {
_finalizer.attach(this, _ffi.cast());
}
}
static final _finalizer = ffi.NativeFinalizer(
ffi.Native.addressOf(_ICU4XIanaToBcp47Mapper_destroy));
/// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47Mapper.html#method.new) for more information.
///
/// Throws [Error] on failure.
factory IanaToBcp47Mapper(DataProvider provider) {
final result = _ICU4XIanaToBcp47Mapper_create(provider._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return IanaToBcp47Mapper._fromFfi(result.union.ok, []);
}
/// See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47MapperBorrowed.html#method.get) for more information.
///
/// See the [Rust documentation for `iana_to_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapperBorrowed.html#method.iana_to_bcp47) for more information.
///
/// Throws [Error] on failure.
String operator [](String value) {
final temp = ffi2.Arena();
final valueView = value.utf8View;
final writeable = _Writeable();
final result = _ICU4XIanaToBcp47Mapper_get(
_ffi, valueView.allocIn(temp), valueView.length, writeable._ffi);
temp.releaseAll();
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
}
@meta.ResourceIdentifier('ICU4XIanaToBcp47Mapper_destroy')
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
isLeaf: true, symbol: 'ICU4XIanaToBcp47Mapper_destroy')
// ignore: non_constant_identifier_names
external void _ICU4XIanaToBcp47Mapper_destroy(ffi.Pointer<ffi.Void> self);
@meta.ResourceIdentifier('ICU4XIanaToBcp47Mapper_create')
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XIanaToBcp47Mapper_create')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _ICU4XIanaToBcp47Mapper_create(
ffi.Pointer<ffi.Opaque> provider);
@meta.ResourceIdentifier('ICU4XIanaToBcp47Mapper_get')
@ffi.Native<
_ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>,
ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XIanaToBcp47Mapper_get')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XIanaToBcp47Mapper_get(
ffi.Pointer<ffi.Opaque> self,
ffi.Pointer<ffi.Uint8> valueData,
int valueLength,
ffi.Pointer<ffi.Opaque> writeable);