feat: Move the Result type into moxlib
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
Now, `import 'package:moxlib/moxlib.dart';` is enough.
This commit is contained in:
parent
3d3b047097
commit
5e867e30ee
@ -1,4 +1,5 @@
|
|||||||
library moxlib;
|
library moxlib;
|
||||||
|
|
||||||
export 'awaitabledatasender.dart';
|
export 'src/awaitabledatasender.dart';
|
||||||
export 'math.dart';
|
export 'src/math.dart';
|
||||||
|
export 'src/result.dart';
|
||||||
|
24
lib/src/result.dart
Normal file
24
lib/src/result.dart
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/// Holds a value of either [T] or [V].
|
||||||
|
class Result<T, V> {
|
||||||
|
/// Constructs a result. [_data] must be either of type [T] or [V].
|
||||||
|
const Result(this._data)
|
||||||
|
: assert(
|
||||||
|
_data is T || _data is V,
|
||||||
|
'Invalid data type $_data: Must be either $T or $V',
|
||||||
|
);
|
||||||
|
final dynamic _data;
|
||||||
|
|
||||||
|
/// Returns true if the data contained within is of type [S]. If not, returns false.
|
||||||
|
bool isType<S>() => _data is S;
|
||||||
|
|
||||||
|
/// Returns the data contained within cast to [S]. Before doing this call, it's recommended
|
||||||
|
/// to check isType<S>() first.
|
||||||
|
S get<S>() {
|
||||||
|
assert(_data is S, 'Data is not $S');
|
||||||
|
|
||||||
|
return _data as S;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the runtime type of the data.
|
||||||
|
Object get dataRuntimeType => _data.runtimeType;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
name: moxlib
|
name: moxlib
|
||||||
description: A collection of code for sharing between various moxxy libraries. Not intended for outside use.
|
description: A collection of code for sharing between various moxxy libraries. Not intended for outside use.
|
||||||
version: 0.1.5
|
version: 0.2.0
|
||||||
homepage: https://codeberg.org/moxxy/moxlib
|
homepage: https://codeberg.org/moxxy/moxlib
|
||||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:moxlib/awaitabledatasender.dart';
|
import 'package:moxlib/moxlib.dart';
|
||||||
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
class TestDataType implements JsonImplementation {
|
class TestDataType implements JsonImplementation {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:moxlib/math.dart';
|
import 'package:moxlib/moxlib.dart';
|
||||||
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user