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