BidiMirroringGlyph.mjs (5428B)
1 // generated by diplomat-tool 2 import { BidiPairedBracketType } from "./BidiPairedBracketType.mjs" 3 import wasm from "./diplomat-wasm.mjs"; 4 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7 /** 8 * See the [Rust documentation for `BidiMirroringGlyph`](https://docs.rs/icu/latest/icu/properties/props/struct.BidiMirroringGlyph.html) for more information. 9 */ 10 11 12 export class BidiMirroringGlyph { 13 #mirroringGlyph; 14 get mirroringGlyph() { 15 return this.#mirroringGlyph; 16 } 17 set mirroringGlyph(value){ 18 this.#mirroringGlyph = value; 19 } 20 #mirrored; 21 get mirrored() { 22 return this.#mirrored; 23 } 24 set mirrored(value){ 25 this.#mirrored = value; 26 } 27 #pairedBracketType; 28 get pairedBracketType() { 29 return this.#pairedBracketType; 30 } 31 set pairedBracketType(value){ 32 this.#pairedBracketType = value; 33 } 34 /** Create `BidiMirroringGlyph` from an object that contains all of `BidiMirroringGlyph`s fields. 35 * Optional fields do not need to be included in the provided object. 36 */ 37 static fromFields(structObj) { 38 return new BidiMirroringGlyph(structObj); 39 } 40 41 #internalConstructor(structObj) { 42 if (typeof structObj !== "object") { 43 throw new Error("BidiMirroringGlyph's constructor takes an object of BidiMirroringGlyph's fields."); 44 } 45 46 if ("mirroringGlyph" in structObj) { 47 this.#mirroringGlyph = structObj.mirroringGlyph; 48 } else { 49 this.#mirroringGlyph = null; 50 } 51 52 if ("mirrored" in structObj) { 53 this.#mirrored = structObj.mirrored; 54 } else { 55 throw new Error("Missing required field mirrored."); 56 } 57 58 if ("pairedBracketType" in structObj) { 59 this.#pairedBracketType = structObj.pairedBracketType; 60 } else { 61 throw new Error("Missing required field pairedBracketType."); 62 } 63 64 return this; 65 } 66 67 // Return this struct in FFI function friendly format. 68 // Returns an array that can be expanded with spread syntax (...) 69 _intoFFI( 70 functionCleanupArena, 71 appendArrayMap 72 ) { 73 return [...diplomatRuntime.optionToArgsForCalling(this.#mirroringGlyph, 4, 4, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue, Uint32Array)]), this.#mirrored, /* [3 x i8] padding */ 0, 0, 0 /* end padding */, this.#pairedBracketType.ffiValue] 74 } 75 76 static _fromSuppliedValue(internalConstructor, obj) { 77 if (internalConstructor !== diplomatRuntime.internalConstructor) { 78 throw new Error("_fromSuppliedValue cannot be called externally."); 79 } 80 81 if (obj instanceof BidiMirroringGlyph) { 82 return obj; 83 } 84 85 return BidiMirroringGlyph.fromFields(obj); 86 } 87 88 _writeToArrayBuffer( 89 arrayBuffer, 90 offset, 91 functionCleanupArena, 92 appendArrayMap 93 ) { 94 diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#mirroringGlyph, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue, Uint32Array)); 95 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#mirrored, Uint8Array); 96 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 12, this.#pairedBracketType.ffiValue, Int32Array); 97 } 98 99 // This struct contains borrowed fields, so this takes in a list of 100 // "edges" corresponding to where each lifetime's data may have been borrowed from 101 // and passes it down to individual fields containing the borrow. 102 // This method does not attempt to handle any dependencies between lifetimes, the caller 103 // should handle this when constructing edge arrays. 104 static _fromFFI(internalConstructor, ptr) { 105 if (internalConstructor !== diplomatRuntime.internalConstructor) { 106 throw new Error("BidiMirroringGlyph._fromFFI is not meant to be called externally. Please use the default constructor."); 107 } 108 let structObj = {}; 109 const mirroringGlyphDeref = ptr; 110 structObj.mirroringGlyph = diplomatRuntime.readOption(wasm, mirroringGlyphDeref, 4, (wasm, offset) => { const deref = (new Uint32Array(wasm.memory.buffer, offset, 1))[0]; return deref }); 111 const mirroredDeref = (new Uint8Array(wasm.memory.buffer, ptr + 8, 1))[0] === 1; 112 structObj.mirrored = mirroredDeref; 113 const pairedBracketTypeDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12); 114 structObj.pairedBracketType = new BidiPairedBracketType(diplomatRuntime.internalConstructor, pairedBracketTypeDeref); 115 116 return new BidiMirroringGlyph(structObj); 117 } 118 119 120 /** 121 * See the [Rust documentation for `for_char`](https://docs.rs/icu/latest/icu/properties/props/trait.EnumeratedProperty.html#tymethod.for_char) for more information. 122 */ 123 static forChar(ch) { 124 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 16, 4, false); 125 126 127 const result = wasm.icu4x_BidiMirroringGlyph_for_char_mv1(diplomatReceive.buffer, ch); 128 129 try { 130 return BidiMirroringGlyph._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer); 131 } 132 133 finally { 134 diplomatReceive.free(); 135 } 136 } 137 138 constructor(structObj) { 139 return this.#internalConstructor(...arguments) 140 } 141 }