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/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ memory model for values whose address is reinterpreted, without a consumer.
- [Parts of arrays without arrayView](/quest/m3/ts-slice-object.md) - a `&mut [T; N]` to part of an array is taken where it is, with no `Proxy`
- [Throw only where Rust panics](/quest/m3/ts-runtime-throws.md) - no runtime `rust2-ts:` error where native Rust goes on: an exact slower path, or a refusal at translation
- [rust2-ts with no ts.toml](/quest/m3/ts-configless.md) - a crate's whole `pub` API translates with no config and no bound items
- [A slice of one byte's place](/quest/m3/ts-byte-slice-place.md) - `slice::from_mut` of a `&mut u8` writes the byte where the caller holds it
- [Browser APIs through wasm-bindgen](/quest/m3/ts-wasm-bindgen/README.md) - web-sys and js-sys imports become direct JS calls, so idiomatic crates such as web-rs's web-codecs translate as stock crates
- [Fields typed by an associated type](/quest/m3/ts-assoc-type-fields.md) - a generic struct's field of `<T as Trait>::Item` translates at each instance
24 changes: 0 additions & 24 deletions quest/m3/ts-byte-slice-place.md

This file was deleted.

4 changes: 2 additions & 2 deletions quest/m3/ts-slice-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ go. Proven by differential tests against native Rust.
- (b) Bytes only: `as_chunks_mut` makes eager `subarray` views, keeping the `Proxy`
path for other elements.
- (c) Keep the `Proxy` views and drop the item.
2. `slice::from_mut` of a `&mut u8`: kept, deferred to
[a quest of its own](/quest/m3/ts-byte-slice-place.md).
2. `slice::from_mut` of a `&mut u8`: kept, deferred to a quest of its own, since done
([moq-dev/rust2#660](https://github.com/moq-dev/rust2/pull/660)).
3. Comparing `*const [T]` of values JS copies: moved to
[Throw only where Rust panics](/quest/m3/ts-runtime-throws.md).

Expand Down
12 changes: 10 additions & 2 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `Vec<T>` | `rs.Vec<T>`: its items, the array `items`, and the capacity std's holds; `rs.vecFrom(items)` makes one of an array with room for exactly them. `rs.ByteVec` of bytes |
| `Cow<[T]>`, `Cow<str>` | `rs.Cow<T>`: the `Vec` it owns, or an `rs.Borrowed` holding the slice it borrows, `rs.Cow<T, rs.ArraySlice<S>>` holding the arrays of a slice of arrays; `rs.ByteCow` for bytes, an `rs.ByteVec` or an `rs.ByteSlice`; `rs.StrCow` for text, the `rs.String` it owns or an `rs.Borrowed` holding the string it borrows, whose text `rs.strCowStr` reads |
| `&T`, `&mut T`, `Box<T>`, `Reverse<T>`, `NonZero<T>`, `AssertUnwindSafe<T>` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a reference, or to an `Arc`, a `Waker`, or a `LocalKey`, whose copies share what it points at, is an `rs.Place<T>`, which for what a box holds is the place holding the box |
| `*const T`, `*mut T`, `NonNull<T>` | what a `&mut T` is: the object, an `rs.Slice` of a `[T; N]`'s elements or an `rs.ByteSlice` of a `[u8; N]`'s bytes, which compares by the array or buffer and offset they are at, refused for an array of one, which `array::from_ref`, `from_mut` of a variable, and `Option::as_slice` make of their own, or an `rs.Place<T>` to a value JS copies and to a library type such as a `Vec` or an `Arc`, which into an array, slice, or `Vec` is the `rs.AtIndex` of its element, which `add`, `sub`, `offset`, their wrapping forms, `offset_from`, `ptr::copy`, `write_bytes` of bytes, and `slice::from_raw_parts` move, measure, copy between, set, and view; one to a value in no array is element 0 of an array of one, as in Rust, but a byte variable whose `&raw` the body takes, or that of a reference to it made there, as `&mut b as *mut u8` does, is element 0 of a `Uint8Array` of its own, which its raw, mutable, and shared slices view as they do any other bytes; JS keeps an array of one, and a shared subslice of a byte in no array, which JS copies, apart from what holds it in Rust, so a pointer, slice, copy, or write of bytes the body shows reaching past either, and `offset_from` between pointers the body shows JS keeps in different arrays, are refused, and through a pointer from elsewhere any of these, a raw or mutable slice of a byte in no array, such as a field's, or a read or write past the array JS keeps it in but for a `Vec`'s room up to its capacity, fails at run time; a pointer into an array of values JS keeps as objects is refused, as is comparing pointers to other values JS copies, each a place JS makes of its own; `rs.NULL` for null and `rs.DANGLING` for dangling. `str::as_ptr` points into the text's UTF-8, which JS encodes anew at each call, so a read through it reads what Rust's does and a write, or a mutable slice, through it, which Rust forbids, fails at run time, as do a read before its first byte, such as a substring's pointer moved back into its text's bytes, and `offset_from` between two calls' pointers, each refused where the body shows it. A pointer to a slice cast to one to an array of its elements is the `rs.Slice` or `rs.ByteSlice` of that many from its first, read through only where Rust reads. A `*const ()` is an identity, such as a waker's data, and `rs.DANGLING_UNIT` when dangling; one to a place of `()` or from a reference to one is refused. A pointer to a value JS keeps as an object cast to one, by `as` or `cast`, is the same object, which `rs.ptrErase` notes the type of, so a cast back to a pointer to another type fails at run time, and null and dangling stay so, dangling at the alignment of the type it was cast from; one to a value JS copies is the same place where an `Arc`'s or `Rc`'s `into_raw` or `as_ptr` gave it, its value's one place, which `rs.arcErase` checks where the body doesn't show it, and refused where the body shows a borrow's, a new place each borrow, as is casting one to a view of bytes, a new one each borrow, or one of no fixed size. A write of a whole object copies into it one object deep, as an assignment through a `&mut` does, the state an `rs` class such as `rs.LazyCell` keeps private included, so a pointer to a part kept as an object, such as a field of a tuple or struct type, is refused wherever the crate may put another object there while a pointer into that memory may still be read, which a write into a fresh allocation, or a variable before any pointer into it is taken, can't, whether by index or through std's iterators over its slots; a read copies what the crate writes into in place |
| `*const T`, `*mut T`, `NonNull<T>` | what a `&mut T` is: the object, an `rs.Slice` of a `[T; N]`'s elements or an `rs.ByteSlice` of a `[u8; N]`'s bytes, which compares by the array or buffer and offset they are at, refused for an array of one, which `array::from_ref`, `from_mut` of a variable, and `Option::as_slice` make of their own, or an `rs.Place<T>` to a value JS copies and to a library type such as a `Vec` or an `Arc`, which into an array, slice, or `Vec` is the `rs.AtIndex` of its element, which `add`, `sub`, `offset`, their wrapping forms, `offset_from`, `ptr::copy`, `write_bytes` of bytes, and `slice::from_raw_parts` move, measure, copy between, set, and view; one to a value in no array is element 0 of an array of one, as in Rust, but a byte variable whose `&raw` the body takes, or that of a reference to it made there, as `&mut b as *mut u8` does, or of whose `&mut` it makes a slice of one, is element 0 of a `Uint8Array` of its own, which its raw, mutable, and shared slices view as they do any other bytes; JS keeps an array of one, and a shared subslice of a byte in no array, which JS copies, apart from what holds it in Rust, so a pointer, slice, copy, or write of bytes the body shows reaching past either, and `offset_from` between pointers the body shows JS keeps in different arrays, are refused, and through a pointer from elsewhere any of these, a raw or mutable slice of a byte in no array, such as a field's, or a read or write past the array JS keeps it in but for a `Vec`'s room up to its capacity, fails at run time; a pointer into an array of values JS keeps as objects is refused, as is comparing pointers to other values JS copies, each a place JS makes of its own; `rs.NULL` for null and `rs.DANGLING` for dangling. `str::as_ptr` points into the text's UTF-8, which JS encodes anew at each call, so a read through it reads what Rust's does and a write, or a mutable slice, through it, which Rust forbids, fails at run time, as do a read before its first byte, such as a substring's pointer moved back into its text's bytes, and `offset_from` between two calls' pointers, each refused where the body shows it. A pointer to a slice cast to one to an array of its elements is the `rs.Slice` or `rs.ByteSlice` of that many from its first, read through only where Rust reads. A `*const ()` is an identity, such as a waker's data, and `rs.DANGLING_UNIT` when dangling; one to a place of `()` or from a reference to one is refused. A pointer to a value JS keeps as an object cast to one, by `as` or `cast`, is the same object, which `rs.ptrErase` notes the type of, so a cast back to a pointer to another type fails at run time, and null and dangling stay so, dangling at the alignment of the type it was cast from; one to a value JS copies is the same place where an `Arc`'s or `Rc`'s `into_raw` or `as_ptr` gave it, its value's one place, which `rs.arcErase` checks where the body doesn't show it, and refused where the body shows a borrow's, a new place each borrow, as is casting one to a view of bytes, a new one each borrow, or one of no fixed size. A write of a whole object copies into it one object deep, as an assignment through a `&mut` does, the state an `rs` class such as `rs.LazyCell` keeps private included, so a pointer to a part kept as an object, such as a field of a tuple or struct type, is refused wherever the crate may put another object there while a pointer into that memory may still be read, which a write into a fresh allocation, or a variable before any pointer into it is taken, can't, whether by index or through std's iterators over its slots; a read copies what the crate writes into in place |
| `MaybeUninit<T>` | `T`: `undefined` until written, `0` for a byte, or an object whose parts kept as objects are there, holding `undefined`, as `Box::new_uninit` and each of `Box::new_uninit_slice`'s is; a slice's `write_clone_of_slice` clones into its slots without dropping what they held. `Box::new_zeroed`'s holds the value of zero bytes in each part they are one of, such as a number, `false`, `None`, a null pointer, or an enum's variant of a tag or niche of zero, and `undefined` in each part they are none of, such as a reference, for a write to fill before a read |
| `ManuallyDrop<T>` | `T`, which nothing drops but its own `drop`; its `Debug`, comparisons, and constants are refused |
| `union` | an object of slots named by offset, `at0` and `at8`, each holding the field part kept there; fields must overlap in the same type, or in a non-null pointer and an `Option` of it |
Expand Down Expand Up @@ -168,7 +168,15 @@ bytes. A struct's private `&[u8]` or `&[u8; N]` field is its three parts, `bufDa
`bufStart`, and `bufLen` for `buf`, so a cursor moving through it makes no object; a
read that needs the slice whole makes it there. A caller passes bytes as
`rs.byteSliceFrom(array)` and reads a slice it gets as `rs.byteSliceView(slice)`, a view
of it. An `rs.Slice` is the same of other values, a `&[T]`, `&mut [T]`, or `Box<[T]>`:
of it. `slice::from_mut`, `array::from_mut`, and `Option::as_mut_slice` of a byte view it
where the body shows it is in a `Uint8Array`: an element of an array, slice, or `Vec` of
bytes, or a byte variable, which one of its own then holds. Any other byte, such as a
field's or one a parameter points at, they copy into an `rs.ByteMirror`, and the function
writes the copy back after each statement or call that may write through the slice,
whenever the byte changed, as Rust reaches the byte only through the slice while it is in
use. A slice of a copy kept where no variable of the function holds it, such as in what
it returns or in memory a parameter points at, or that may still be used once its call
makes another, is refused. An `rs.Slice` is the same of other values, a `&[T]`, `&mut [T]`, or `Box<[T]>`:
its `data`, a JS array, from `start`, for `length` elements, read and written where they
are, so `&mut v[a..b]`, `split_at_mut`, `chunks_mut`, and `split_mut` lend parts of the
same array. A caller passes one as `rs.sliceFrom(array)` and reads one it gets as
Expand Down
31 changes: 31 additions & 0 deletions ts/fixtures/lang/conversions/expected/conversions.Cursor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Generated by rust2-ts. Do not edit.

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

/** Reads bytes off the front of a slice, as a decoder does. */
export interface Cursor {
dataData: Uint8Array;
dataStart: number;
dataLen: number;
}

/** Fills `buf` from the front, or leaves it as it is if too few are left. */
export function readExact(self: Cursor, buf: rs.ByteSlice): boolean {
if (!(self.dataLen < buf.length)) {
const _14Data: Uint8Array = self.dataData;
const _14Start: number = self.dataStart;
const _14Len: number = self.dataLen;
const mid: number = buf.length;
if (mid > _14Len) {
rs.panic("mid > len");
}
rs.byteSliceCopyFromSlice(buf, new rs.ByteSlice(_14Data, _14Start, mid));
self.dataData = _14Data;
self.dataStart = _14Start + mid;
self.dataLen = _14Len - mid;
return true;
}
return false;
}

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

import * as rs from "./rs.ts";
import { mapOr$0vxw5sq as option_mapOr$0vxw5sq } from "./core/option.ts";

/**
* Bytes in each place a `&mut u8` reaches: fields, a tuple's, an array's, an `Option`'s,
* and a `MaybeUninit`'s.
*/
export interface Header {
tag: rs.u8;
pair: [rs.u8, rs.u8];
bytes: Uint8Array;
payload: rs.u8 | undefined;
uninit: rs.u8;
}

/** Each byte, the `MaybeUninit`'s once written. */
export function put(self: Header, out: rs.ByteVec): void {
rs.iterExtendBytes(out, rs.iterSlice(Uint8Array.of(self.tag, self.pair[0], self.pair[1], self.bytes[0], self.bytes[1])), undefined, true);
rs.byteVecPush(out, option_mapOr$0vxw5sq(self.payload, 238, (p: rs.u8): rs.u8 => {
return p ^ 128;
}));
}

/** Adds `by` to its tag through a slice of one of it. */
export function bump(self: Header, by: rs.u8): void {
let mirror!: rs.ByteMirror | undefined;
const _4: rs.ByteSlice = (mirror = rs.byteMirror(rs.place(() => self.tag, (value) => self.tag = value))).s;
const iterS: Uint8Array = _4.data;
let iterI: number = _4.start;
const iterE: number = _4.start + _4.length;
rs.byteMirrorFlush(mirror);
while (true) {
const _7: number | rs.Done = iterI < iterE ? iterI++ : rs.DONE;
rs.byteMirrorFlush(mirror);
if (_7 === rs.DONE) {
break;
}
iterS[_7] = rs.u8WrappingAdd(iterS[_7], by);
rs.byteMirrorFlush(mirror);
}
}

//# sourceMappingURL=conversions.Header.ts.map
Loading