happy-rusty 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.cn.md +5 -3
- package/README.md +8 -6
- package/dist/types.d.ts +12 -0
- package/package.json +1 -1
- package/src/mod.ts +16 -0
package/README.cn.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# 在JavaScript中使用Rust特性
|
|
2
|
+
|
|
1
3
|
[](https://npmjs.org/package/happy-rusty)
|
|
2
4
|
[](https://jsr.io/@happy-js/happy-rusty)
|
|
3
5
|
[](https://jsr.io/@happy-js/happy-rusty/score)
|
|
4
6
|
[](https://github.com/jiangjie/happy-rusty/actions/workflows/test.yml)
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
---
|
|
7
9
|
|
|
8
10
|
## 部分支持的特性
|
|
9
11
|
|
|
@@ -46,13 +48,13 @@ bunx jsr add @happy-js/happy-rusty
|
|
|
46
48
|
|
|
47
49
|
接下来就可以在代码里引用了。
|
|
48
50
|
```ts
|
|
49
|
-
import { Some, None, Ok, Err } from '
|
|
51
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
## 示例
|
|
53
55
|
|
|
54
56
|
```ts
|
|
55
|
-
import { Some, None, Ok, Err } from '
|
|
57
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
56
58
|
|
|
57
59
|
function judge(n: number): Option<Promise<Result<number, Error>>> {
|
|
58
60
|
if (n < 0 || n >= 1) {
|
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="README.cn.md">[中文]</a>
|
|
3
|
-
</p>
|
|
1
|
+
# Use Rust features in JavaScript happily
|
|
4
2
|
|
|
5
3
|
[](https://npmjs.org/package/happy-rusty)
|
|
6
4
|
[](https://jsr.io/@happy-js/happy-rusty)
|
|
7
5
|
[](https://jsr.io/@happy-js/happy-rusty/score)
|
|
8
6
|
[](https://github.com/jiangjie/happy-rusty/actions/workflows/test.yml)
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<a href="README.cn.md">[中文]</a>
|
|
11
|
+
|
|
12
|
+
---
|
|
11
13
|
|
|
12
14
|
## Partial supported
|
|
13
15
|
|
|
@@ -50,7 +52,7 @@ bunx jsr add @happy-js/happy-rusty
|
|
|
50
52
|
|
|
51
53
|
then import to your code.
|
|
52
54
|
```ts
|
|
53
|
-
import { Some, None, Ok, Err } from '
|
|
55
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
Enjoy the happiness.
|
|
@@ -58,7 +60,7 @@ Enjoy the happiness.
|
|
|
58
60
|
## Examples
|
|
59
61
|
|
|
60
62
|
```ts
|
|
61
|
-
import { Some, None, Ok, Err } from '
|
|
63
|
+
import { Some, None, Ok, Err } from 'happy-rusty';
|
|
62
64
|
|
|
63
65
|
function judge(n: number): Option<Promise<Result<number, Error>>> {
|
|
64
66
|
if (n < 0 || n >= 1) {
|
package/dist/types.d.ts
CHANGED
|
@@ -124,9 +124,21 @@ interface Err<T, E> {
|
|
|
124
124
|
*/
|
|
125
125
|
declare function Err<T, E>(error: E): Result<T, E>;
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* The shorthand of Promise<Option<T>>.
|
|
129
|
+
*/
|
|
127
130
|
type AsyncOption<T> = Promise<Option<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* The shorthand of Promise<Result<T, E>>.
|
|
133
|
+
*/
|
|
128
134
|
type AsyncResult<T, E> = Promise<Result<T, E>>;
|
|
135
|
+
/**
|
|
136
|
+
* The shorthand of Result<T, Error>.
|
|
137
|
+
*/
|
|
129
138
|
type IOResult<T> = Result<T, Error>;
|
|
139
|
+
/**
|
|
140
|
+
* The shorthand of Promise<Result<T, Error>>.
|
|
141
|
+
*/
|
|
130
142
|
type AsyncIOResult<T> = Promise<IOResult<T>>;
|
|
131
143
|
|
|
132
144
|
export { type AsyncIOResult, type AsyncOption, type AsyncResult, Err, type IOResult, None, Ok, type Option, type Result, Some };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Porting some excellent design implementations from Rust to JavaScript.",
|
|
4
4
|
"author": "jiang115jie@gmail.com",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.9",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"source": "src/mod.ts",
|
|
9
9
|
"main": "dist/main.cjs",
|
package/src/mod.ts
CHANGED
|
@@ -5,7 +5,23 @@ export { None, Some, type Option } from './enum/option.ts';
|
|
|
5
5
|
export { Err, Ok, type Result } from './enum/result.ts';
|
|
6
6
|
|
|
7
7
|
// export some commonly used types
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The shorthand of Promise<Option<T>>.
|
|
11
|
+
*/
|
|
8
12
|
export type AsyncOption<T> = Promise<Option<T>>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The shorthand of Promise<Result<T, E>>.
|
|
16
|
+
*/
|
|
9
17
|
export type AsyncResult<T, E> = Promise<Result<T, E>>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The shorthand of Result<T, Error>.
|
|
21
|
+
*/
|
|
10
22
|
export type IOResult<T> = Result<T, Error>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The shorthand of Promise<Result<T, Error>>.
|
|
26
|
+
*/
|
|
11
27
|
export type AsyncIOResult<T> = Promise<IOResult<T>>;
|