1// generated by diplomat-tool 2import { LineBreakStrictness } from "./LineBreakStrictness.mjs" 3import { LineBreakWordOption } from "./LineBreakWordOption.mjs" 4import wasm from "./diplomat-wasm.mjs"; 5import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8/** See the [Rust documentation for `LineBreakOptions`](https://docs.rs/icu/latest/icu/segmenter/options/struct.LineBreakOptions.html) for more information. 9*/ 10 11 12export class LineBreakOptions { 13 14 #strictness; 15 16 get strictness() { 17 return this.#strictness; 18 } 19 set strictness(value) { 20 this.#strictness = value; 21 } 22 23 #wordOption; 24 25 get wordOption() { 26 return this.#wordOption; 27 } 28 set wordOption(value) { 29 this.#wordOption = value; 30 } 31 32 /** Create `LineBreakOptions` from an object that contains all of `LineBreakOptions`s fields. 33 * Optional fields do not need to be included in the provided object. 34 */ 35 static fromFields(structObj) { 36 return new LineBreakOptions(structObj); 37 } 38 39 #internalConstructor(structObj) { 40 if (typeof structObj !== "object") { 41 throw new Error("LineBreakOptions's constructor takes an object of LineBreakOptions's fields."); 42 } 43 44 if ("strictness" in structObj) { 45 this.#strictness = structObj.strictness; 46 } else { 47 this.#strictness = null; 48 } 49 50 if ("wordOption" in structObj) { 51 this.#wordOption = structObj.wordOption; 52 } else { 53 this.#wordOption = null; 54 } 55 56 return this; 57 } 58 59 // Return this struct in FFI function friendly format. 60 // Returns an array that can be expanded with spread syntax (...) 61 62 _intoFFI( 63 functionCleanupArena, 64 appendArrayMap 65 ) { 66 return [...diplomatRuntime.optionToArgsForCalling(this.#strictness, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)]), ...diplomatRuntime.optionToArgsForCalling(this.#wordOption, 4, 4, false, (arrayBuffer, offset, jsValue) => [diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)])] 67 } 68 69 static _fromSuppliedValue(internalConstructor, obj) { 70 if (internalConstructor !== diplomatRuntime.internalConstructor) { 71 throw new Error("_fromSuppliedValue cannot be called externally."); 72 } 73 74 if (obj instanceof LineBreakOptions) { 75 return obj; 76 } 77 78 return LineBreakOptions.fromFields(obj); 79 } 80 81 _writeToArrayBuffer( 82 arrayBuffer, 83 offset, 84 functionCleanupArena, 85 appendArrayMap 86 ) { 87 diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#strictness, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); 88 diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 8, this.#wordOption, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.ffiValue, Int32Array)); 89 } 90 91 // This struct contains borrowed fields, so this takes in a list of 92 // "edges" corresponding to where each lifetime's data may have been borrowed from 93 // and passes it down to individual fields containing the borrow. 94 // This method does not attempt to handle any dependencies between lifetimes, the caller 95 // should handle this when constructing edge arrays. 96 static _fromFFI(internalConstructor, ptr) { 97 if (internalConstructor !== diplomatRuntime.internalConstructor) { 98 throw new Error("LineBreakOptions._fromFFI is not meant to be called externally. Please use the default constructor."); 99 } 100 let structObj = {}; 101 const strictnessDeref = ptr; 102 structObj.strictness = diplomatRuntime.readOption(wasm, strictnessDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new LineBreakStrictness(diplomatRuntime.internalConstructor, deref) }); 103 const wordOptionDeref = ptr + 8; 104 structObj.wordOption = diplomatRuntime.readOption(wasm, wordOptionDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new LineBreakWordOption(diplomatRuntime.internalConstructor, deref) }); 105 106 return new LineBreakOptions(structObj); 107 } 108 109 constructor(structObj) { 110 return this.#internalConstructor(...arguments) 111 } 112}