| // generated by diplomat-tool |
| |
| part of 'lib.g.dart'; |
| |
| /// An ICU4X Fixed Decimal Format object, capable of formatting a [`FixedDecimal`] as a string. |
| /// |
| /// See the [Rust documentation for `FixedDecimalFormatter`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html) for more information. |
| final class FixedDecimalFormatter 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. |
| FixedDecimalFormatter._fromFfi(this._ffi, this._selfEdge) { |
| if (_selfEdge.isEmpty) { |
| _finalizer.attach(this, _ffi.cast()); |
| } |
| } |
| |
| @_DiplomatFfiUse('ICU4XFixedDecimalFormatter_destroy') |
| static final _finalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf(_ICU4XFixedDecimalFormatter_destroy), |
| ); |
| |
| /// Creates a new [`FixedDecimalFormatter`] from locale data. |
| /// |
| /// See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.try_new) for more information. |
| /// |
| /// Throws [Error] on failure. |
| factory FixedDecimalFormatter.withGroupingStrategy( |
| DataProvider provider, |
| Locale locale, |
| FixedDecimalGroupingStrategy groupingStrategy, |
| ) { |
| final result = _ICU4XFixedDecimalFormatter_create_with_grouping_strategy( |
| provider._ffi, |
| locale._ffi, |
| groupingStrategy.index, |
| ); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return FixedDecimalFormatter._fromFfi(result.union.ok, []); |
| } |
| |
| /// Formats a [`FixedDecimal`] to a string. |
| /// |
| /// See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.format) for more information. |
| /// |
| /// Throws [Error] on failure. |
| String format(FixedDecimal value) { |
| final writeable = _Writeable(); |
| final result = _ICU4XFixedDecimalFormatter_format( |
| _ffi, |
| value._ffi, |
| writeable._ffi, |
| ); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return writeable.finalize(); |
| } |
| } |
| |
| @_DiplomatFfiUse('ICU4XFixedDecimalFormatter_destroy') |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| isLeaf: true, |
| symbol: 'ICU4XFixedDecimalFormatter_destroy', |
| ) |
| // ignore: non_constant_identifier_names |
| external void _ICU4XFixedDecimalFormatter_destroy(ffi.Pointer<ffi.Void> self); |
| |
| @_DiplomatFfiUse('ICU4XFixedDecimalFormatter_create_with_grouping_strategy') |
| @ffi.Native< |
| _ResultOpaqueInt32 Function( |
| ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Opaque>, |
| ffi.Int32, |
| ) |
| >( |
| isLeaf: true, |
| symbol: 'ICU4XFixedDecimalFormatter_create_with_grouping_strategy', |
| ) |
| // ignore: non_constant_identifier_names |
| external _ResultOpaqueInt32 |
| _ICU4XFixedDecimalFormatter_create_with_grouping_strategy( |
| ffi.Pointer<ffi.Opaque> provider, |
| ffi.Pointer<ffi.Opaque> locale, |
| int groupingStrategy, |
| ); |
| |
| @_DiplomatFfiUse('ICU4XFixedDecimalFormatter_format') |
| @ffi.Native< |
| _ResultVoidInt32 Function( |
| ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Opaque>, |
| ) |
| >(isLeaf: true, symbol: 'ICU4XFixedDecimalFormatter_format') |
| // ignore: non_constant_identifier_names |
| external _ResultVoidInt32 _ICU4XFixedDecimalFormatter_format( |
| ffi.Pointer<ffi.Opaque> self, |
| ffi.Pointer<ffi.Opaque> value, |
| ffi.Pointer<ffi.Opaque> writeable, |
| ); |