impl ToNapiValue for Result<T>
This commit is contained in:
parent
032861c5bc
commit
0d018a5470
9 changed files with 53 additions and 39 deletions
examples/napi
|
@ -12,11 +12,12 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function getNums(): Array<number>␊
|
||||
export function sumNums(nums: Array<number>): number␊
|
||||
export function getCwd(callback: (arg0: string) => void): void␊
|
||||
export function readFile(callback: (arg0: Error | null, arg1: string | undefined) => void): void␊
|
||||
export function readFile(callback: (arg0: Error | undefined, arg1: string | null) => void): void␊
|
||||
export enum Kind { Dog = 0, Cat = 1, Duck = 2 }␊
|
||||
export enum CustomNumEnum { One = 1, Two = 2, Three = 3, Four = 4, Six = 6, Eight = 8, Nine = 9, Ten = 10 }␊
|
||||
export function enumToI32(e: CustomNumEnum): number␊
|
||||
export function mapOption(val: number | undefined): number | undefined␊
|
||||
export function getError(): Error | undefined␊
|
||||
export function mapOption(val: number | null): number | null␊
|
||||
export function add(a: number, b: number): number␊
|
||||
export function fibonacci(n: number): number␊
|
||||
export function listObjKeys(obj: object): Array<string>␊
|
||||
|
|
Binary file not shown.
|
@ -19,6 +19,7 @@ import {
|
|||
createObj,
|
||||
mapOption,
|
||||
readFile,
|
||||
getError,
|
||||
} from '../'
|
||||
|
||||
test('number', (t) => {
|
||||
|
@ -81,7 +82,7 @@ test('callback', (t) => {
|
|||
)
|
||||
|
||||
readFile((err, content) => {
|
||||
t.is(err, null)
|
||||
t.is(err, undefined)
|
||||
t.is(content, 'hello world')
|
||||
})
|
||||
})
|
||||
|
@ -92,6 +93,12 @@ test('object', (t) => {
|
|||
})
|
||||
|
||||
test('Option', (t) => {
|
||||
t.is(mapOption(undefined), undefined)
|
||||
t.is(mapOption(null), null)
|
||||
t.is(mapOption(3), 4)
|
||||
})
|
||||
|
||||
test('Result', (t) => {
|
||||
const error = getError()
|
||||
t.not(error, undefined)
|
||||
t.is(error!.message, 'Manual Error')
|
||||
})
|
||||
|
|
5
examples/napi/index.d.ts
vendored
5
examples/napi/index.d.ts
vendored
|
@ -2,11 +2,12 @@ export function getWords(): Array<string>
|
|||
export function getNums(): Array<number>
|
||||
export function sumNums(nums: Array<number>): number
|
||||
export function getCwd(callback: (arg0: string) => void): void
|
||||
export function readFile(callback: (arg0: Error | null, arg1: string | undefined) => void): void
|
||||
export function readFile(callback: (arg0: Error | undefined, arg1: string | null) => void): void
|
||||
export enum Kind { Dog = 0, Cat = 1, Duck = 2 }
|
||||
export enum CustomNumEnum { One = 1, Two = 2, Three = 3, Four = 4, Six = 6, Eight = 8, Nine = 9, Ten = 10 }
|
||||
export function enumToI32(e: CustomNumEnum): number
|
||||
export function mapOption(val: number | undefined): number | undefined
|
||||
export function getError(): Error | undefined
|
||||
export function mapOption(val: number | null): number | null
|
||||
export function add(a: number, b: number): number
|
||||
export function fibonacci(n: number): number
|
||||
export function listObjKeys(obj: object): Array<string>
|
||||
|
|
6
examples/napi/src/error.rs
Normal file
6
examples/napi/src/error.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use napi::bindgen_prelude::*;
|
||||
|
||||
#[napi]
|
||||
fn get_error() -> Result<()> {
|
||||
Err(Error::new(Status::InvalidArg, "Manual Error".to_owned()))
|
||||
}
|
|
@ -5,6 +5,7 @@ mod array;
|
|||
mod callback;
|
||||
mod class;
|
||||
mod r#enum;
|
||||
mod error;
|
||||
mod nullable;
|
||||
mod number;
|
||||
mod object;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue