Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m2/ts-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ kept separate since each lands alone; rejected: one quest for `ArrayString`.
## Required

- [Addresses as identity](/quest/m2/ts-model/addresses.md) - `Arc::as_ptr(a) as usize` as a key, which needs a decision
- [Option fields at a unit instance](/quest/m2/ts-model/unit-option-fields.md) - `Idle<()>`'s `Option<T>` field tells `Some(())` from `None`
- [A string's bytes through its pointer](/quest/m2/ts-model/str-as-ptr.md) - `str::as_ptr` reads the string's UTF-8

Public API: the translator's output for moq-net's model.
18 changes: 0 additions & 18 deletions quest/m2/ts-model/unit-option-fields.md

This file was deleted.

20 changes: 13 additions & 7 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `struct` | a plain object, typed by an interface; a class if it may drop |
| `enum` without data | a union of strings: `"Lite01" \| "Lite02"`, or `never` without variants |
| `enum` | a union of objects tagged by variant |
| `Option<T>` | `T \| undefined`; `T \| rs.None` where `T` can already be `undefined`, as `()` and `Option` can, so `Option<()>` and `Option<Option<u64>>` keep `None` apart from each `Some` |
| `Option<T>` | `T \| undefined`; `T \| rs.None` where `T` can already be `undefined`, as `()` and `Option` can, so `Option<()>` and `Option<Option<u64>>` keep `None` apart from each `Some`; a generic type's `Option<T>` is an `rs.OptionOf<T>`, either as each instance's `T` decides, as a generic `Poll<T>` is an `rs.PollOf<T>` |
| `Result<T, E>` | `rs.Result<T, E>`: `{ ok: true, value }` or `{ ok: false, error }`; `rs.OK` or `rs.ERR` where the payload is `undefined`, as in `Ok(())` |
| `ControlFlow<B, C>` | `rs.Result<C, B>`, `Ok` to continue; what `?` branches on is the value it was applied to, but for a `Poll`'s `Pending` and `Ready(None)`, which continue as `Ok` of themselves |
| tuple, `[T; N]`, `&[T; N]` | an array, and `rs.Slice<T>` of all of it for `&[T; N]`; for bytes, `u8` or `MaybeUninit<u8>`, `Uint8Array` for `[u8; N]`, and `rs.ByteSlice` for `&[u8; N]` |
Expand Down Expand Up @@ -467,7 +467,11 @@ in a generic type to what only an instance decides the form of, such as `*mut T`
which each read of an instance's field casts to what it holds. So is a run of a
parameter, whose `u8` instance holds bytes: `[T; N]` is an `rs.ArrayOf<T>`, a `T[]` or a
`Uint8Array`, and `[T]`, `Vec<T>`, and `Cow<[T]>` an `rs.SliceOf<T>`, an `rs.VecOf<T>`,
and an `rs.CowOf<T>`. A type's module exports the
and an `rs.CowOf<T>`. An `Option<T>` or a `Poll<T>` of a parameter is an
`rs.OptionOf<T>` or an `rs.PollOf<T>`, a conditional type TypeScript resolves at each
instance to what that instance's own `Option` or `Poll` is, `T | undefined` or
`T | rs.None`, so a read needs no cast, and a value made into a field is cast to it, which
TypeScript infers the instance's arguments from. A type's module exports the
type by its own name, which a caller writes `Decoder.Decoder`, and a function whose name
and exports it as its own: `function new_` is `Decoder.new`. A module imports a function
or value by its name, and a type's module whole by the type's, `import * as Decoder`,
Expand Down Expand Up @@ -601,9 +605,10 @@ caller can implement. A generic trait's type is generic over the trait's type pa
then the associated types its objects bind that no supertrait binds already, so
`dyn Source<Item = u8>` is a `Source.Source<rs.u8>`, and is typed as the trait declares
it, as a generic struct is: a call casts what it returns to the form its object's
arguments decide, such as the `rs.u8` of an `rs.Ptr<T>`. One whose method takes or returns
another form at its arguments, such as the `rs.None` of an `Option<Self::Item>` whose
`Item` is an `Option` too, is refused. A coercion wraps the value in a class of its type's from `lib.ts`,
arguments decide, such as the `rs.u8` of an `rs.Ptr<T>`. An `Option<Self::Item>` is an
`rs.OptionOf<Item>`, so an `Item` that can be `undefined` returns `rs.None`. One whose
method takes or returns another form at its arguments, such as the `rs.None` of an
`Option<Self::Item>` whose `Item` is a `MaybeUninit<u32>`, typed `number`, is refused. A coercion wraps the value in a class of its type's from `lib.ts`,
named for the type as a suffix spells it, `new of$dyns_Square(sq)`, which every trait's
object of the type shares, whose methods call that type's impls; one from a `&mut` to a
value JS copies holds its `rs.Place`, as `ofPlace$dyns_Square`, so `&mut self` writes
Expand Down Expand Up @@ -1087,13 +1092,14 @@ fields overlap in different types ([unsafe](/quest/m3/ts-unsafe/README.md)), and
behind `&`, `&mut`, `Box`, `Arc`, `Rc`, `Weak`, or `Pin` ([trait objects](/quest/m3/ts-dyn.md)), fail translation. Until they translate, an item that needs one, such as a `Box<dyn Error>` made `From` a string, binds to
hand-written TS ([bindings](#bindings)).

These fail translation: `f16` and `f128`, a `Poll` of a `Poll` of a `Poll`, a future whose output can be pending, an instance of a generic type whose field is a `Poll` of a type parameter that can be pending, a closure that owns a value
These fail translation: `f16` and `f128`, a `Poll` of a `Poll` of a `Poll`, a future whose output can be pending, a closure that owns a value
that drops given to a std function that keeps it other than in an iterator or a
`poll_fn`, or whose mapping doesn't drop it where std's does, a `Cow` of other than `str` or a slice, a std
function without a mapping of its own that makes or reads an `Option` whose `None` is
`rs.None`, an `Option` of an `Option` of `()` or another
`Option`, an instance of a generic type whose field is an `Option` of a type parameter
that can be `undefined`, a `String`'s `capacity`, looking up a key by
that can be `undefined` though TypeScript's type of it can't, as a `MaybeUninit<u32>`
can, or an `Option` or a `Poll` of another form of it whose instance can be `undefined` or pending, a `String`'s `capacity`, looking up a key by
another type it borrows as through the crate's own `Borrow`, a `&mut` to a value JS
copies that std makes, other than a map's, or hands a closure, as `iter_mut` and
`and_modify` do, one into a `Result`'s payload passed on or kept, the adaptors
Expand Down
8 changes: 4 additions & 4 deletions ts/fixtures/lang/collects/expected/collects.Tries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import type * as Item from "./collects.Item.ts";
* a `None`, as nothing stops it from doing.
*/
export class Tries<T> {
_0: rs.Vec<T | undefined>;
_0: rs.Vec<rs.OptionOf<T>>;

constructor(_0: rs.Vec<T | undefined>) {
constructor(_0: rs.Vec<rs.OptionOf<T>>) {
this._0 = _0;
}

Expand All @@ -23,14 +23,14 @@ export function fromIter$iter_FromIterator_collects_Item_collects_Item_iter_adap
const iter2: rs.Iter<Item.Item> = iter;
return new Tries(rs.iterToVec(rs.iterMap(new rs.Range(0, 3), (_2: rs.i32): Item.Item | undefined => {
return rs.iterToOption(iter2.next());
}), undefined, 8, true));
}), undefined, 8, true) as rs.Vec<rs.OptionOf<Item.Item>>);
}

export function fromIter$iter_FromIterator_u8_u8_iter_adapters_GenericShunt_iter_Map_slice_Iter_u8_collects_collects_closure10_Result_never_collects_Item(iter: rs.Iter<rs.u8>): Tries<rs.u8> {
const iter2: rs.Iter<rs.u8> = iter;
return new Tries(rs.iterToVec(rs.iterMap(new rs.Range(0, 3), (_2: rs.i32): rs.u8 | undefined => {
return rs.iterToOption(iter2.next());
}), undefined, 2, true));
}), undefined, 2, true) as rs.Vec<rs.OptionOf<rs.u8>>);
}

//# sourceMappingURL=collects.Tries.ts.map
7 changes: 7 additions & 0 deletions ts/fixtures/lang/dyns/expected/core/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ export function thenSome$0quywni(self: boolean, t: rs.u8): rs.u8 | undefined {
return t;
}

export function thenSome$1n1oy1h(self: boolean, _: undefined): undefined | rs.None {
if (!self) {
return rs.None;
}
return undefined;
}

//# sourceMappingURL=bool.ts.map
22 changes: 22 additions & 0 deletions ts/fixtures/lang/dyns/expected/dyns.Beats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Generated by rust2-ts. Do not edit.

import * as rs from "./rs.ts";

export interface Beats {
_0: rs.u8;
}

export function take$dyns_Source(self: Beats): undefined | rs.None {
const _2: rs.u8 | undefined = rs.u8CheckedSub(self._0, 1);
if (_2 !== undefined) {
self._0 = _2;
return undefined;
}
return rs.None;
}

export function left$dyns_Source(self: Beats): rs.usize {
return self._0 as rs.usize;
}

//# sourceMappingURL=dyns.Beats.ts.map
2 changes: 1 addition & 1 deletion ts/fixtures/lang/dyns/expected/dyns.Over.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Over<T> {
}

export function run$String(self: Over<string>): string | undefined {
const _3: string | undefined = self.source.take$Source();
const _3: string | undefined = self.source.take$Source() as string | undefined;
if (_3 !== undefined) {
const next: string = _3;
const other: string = self.scale.scale$Scaled(next);
Expand Down
11 changes: 11 additions & 0 deletions ts/fixtures/lang/dyns/expected/dyns.Peek.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Generated by rust2-ts. Do not edit.

import * as rs from "./rs.ts";

/**
* A generic trait returning an `Option` of its parameter, which an object's type has as
* an `rs.OptionOf`, at a parameter that can be `undefined`.
*/
export type Peek<T> = { peek$Peek: () => rs.OptionOf<T> };

//# sourceMappingURL=dyns.Peek.ts.map
27 changes: 27 additions & 0 deletions ts/fixtures/lang/dyns/expected/dyns.Skips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Generated by rust2-ts. Do not edit.

import * as rs from "./rs.ts";
import { thenSome$0quywni } from "./core/bool.ts";

/**
* Items that can already be `undefined`, whose `None` is `rs.None`: a countdown's
* remainders, `None` where it skips one, and its ticks.
*/
export interface Skips {
_0: rs.u8;
}

export function take$dyns_Source(self: Skips): rs.u8 | undefined | rs.None {
const _2: rs.u8 | undefined = rs.u8CheckedSub(self._0, 1);
if (_2 !== undefined) {
self._0 = _2;
return thenSome$0quywni(rs.u8Rem(self._0, 3) !== 0, self._0);
}
return rs.None;
}

export function left$dyns_Source(self: Skips): rs.usize {
return self._0 as rs.usize;
}

//# sourceMappingURL=dyns.Skips.ts.map
2 changes: 1 addition & 1 deletion ts/fixtures/lang/dyns/expected/dyns.Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import * as rs from "./rs.ts";

/** A trait with an associated type. */
export type Source<Item> = { take$Source: () => Item | undefined; left$Source: () => rs.usize };
export type Source<Item> = { take$Source: () => rs.OptionOf<Item>; left$Source: () => rs.usize };

//# sourceMappingURL=dyns.Source.ts.map
Loading