1// generated by diplomat-tool 2import wasm from "./diplomat-wasm.mjs"; 3import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6/** Result of a single iteration of [`CodePointRangeIterator`]. 7*Logically can be considered to be an `Option<RangeInclusive<DiplomatChar>>`, 8* 9*`start` and `end` represent an inclusive range of code points [start, end], 10*and `done` will be true if the iterator has already finished. The last contentful 11*iteration will NOT produce a range done=true, in other words `start` and `end` are useful 12*values if and only if `done=false`. 13*/ 14 15 16export class CodePointRangeIteratorResult { 17 18 #start; 19 20 get start() { 21 return this.#start; 22 } 23 24 #end; 25 26 get end() { 27 return this.#end; 28 } 29 30 #done; 31 32 get done() { 33 return this.#done; 34 } 35 36 #internalConstructor(structObj, internalConstructor) { 37 if (typeof structObj !== "object") { 38 throw new Error("CodePointRangeIteratorResult's constructor takes an object of CodePointRangeIteratorResult's fields."); 39 } 40 41 if (internalConstructor !== diplomatRuntime.internalConstructor) { 42 throw new Error("CodePointRangeIteratorResult is an out struct and can only be created internally."); 43 } 44 if ("start" in structObj) { 45 this.#start = structObj.start; 46 } else { 47 throw new Error("Missing required field start."); 48 } 49 50 if ("end" in structObj) { 51 this.#end = structObj.end; 52 } else { 53 throw new Error("Missing required field end."); 54 } 55 56 if ("done" in structObj) { 57 this.#done = structObj.done; 58 } else { 59 throw new Error("Missing required field done."); 60 } 61 62 return this; 63 } 64 65 // Return this struct in FFI function friendly format. 66 // Returns an array that can be expanded with spread syntax (...) 67 68 _intoFFI( 69 functionCleanupArena, 70 appendArrayMap 71 ) { 72 return [this.#start, this.#end, this.#done, /* [3 x i8] padding */ 0, 0, 0 /* end padding */] 73 } 74 75 static _fromSuppliedValue(internalConstructor, obj) { 76 if (internalConstructor !== diplomatRuntime.internalConstructor) { 77 throw new Error("_fromSuppliedValue cannot be called externally."); 78 } 79 80 if (obj instanceof CodePointRangeIteratorResult) { 81 return obj; 82 } 83 84 return CodePointRangeIteratorResult.fromFields(obj); 85 } 86 87 _writeToArrayBuffer( 88 arrayBuffer, 89 offset, 90 functionCleanupArena, 91 appendArrayMap 92 ) { 93 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#start, Uint32Array); 94 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#end, Uint32Array); 95 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#done, Uint8Array); 96 } 97 98 // This struct contains borrowed fields, so this takes in a list of 99 // "edges" corresponding to where each lifetime's data may have been borrowed from 100 // and passes it down to individual fields containing the borrow. 101 // This method does not attempt to handle any dependencies between lifetimes, the caller 102 // should handle this when constructing edge arrays. 103 static _fromFFI(internalConstructor, ptr) { 104 if (internalConstructor !== diplomatRuntime.internalConstructor) { 105 throw new Error("CodePointRangeIteratorResult._fromFFI is not meant to be called externally. Please use the default constructor."); 106 } 107 let structObj = {}; 108 const startDeref = (new Uint32Array(wasm.memory.buffer, ptr, 1))[0]; 109 structObj.start = startDeref; 110 const endDeref = (new Uint32Array(wasm.memory.buffer, ptr + 4, 1))[0]; 111 structObj.end = endDeref; 112 const doneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 8, 1))[0] === 1; 113 structObj.done = doneDeref; 114 115 return new CodePointRangeIteratorResult(structObj, internalConstructor); 116 } 117 118 constructor(structObj, internalConstructor) { 119 return this.#internalConstructor(...arguments) 120 } 121}