1// generated by diplomat-tool 2import { GeneralCategory } from "./GeneralCategory.mjs" 3import wasm from "./diplomat-wasm.mjs"; 4import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7/** A mask that is capable of representing groups of `General_Category` values. 8* 9*See the [Rust documentation for `GeneralCategoryGroup`](https://docs.rs/icu/latest/icu/properties/props/struct.GeneralCategoryGroup.html) for more information. 10*/ 11 12 13export class GeneralCategoryGroup { 14 15 #mask; 16 17 get mask() { 18 return this.#mask; 19 } 20 set mask(value) { 21 this.#mask = value; 22 } 23 24 /** Create `GeneralCategoryGroup` from an object that contains all of `GeneralCategoryGroup`s fields. 25 * Optional fields do not need to be included in the provided object. 26 */ 27 static fromFields(structObj) { 28 return new GeneralCategoryGroup(structObj); 29 } 30 31 #internalConstructor(structObj) { 32 if (typeof structObj !== "object") { 33 throw new Error("GeneralCategoryGroup's constructor takes an object of GeneralCategoryGroup's fields."); 34 } 35 36 if ("mask" in structObj) { 37 this.#mask = structObj.mask; 38 } else { 39 throw new Error("Missing required field mask."); 40 } 41 42 return this; 43 } 44 45 // Return this struct in FFI function friendly format. 46 // Returns an array that can be expanded with spread syntax (...) 47 48 _intoFFI( 49 functionCleanupArena, 50 appendArrayMap 51 ) { 52 return [this.#mask] 53 } 54 55 static _fromSuppliedValue(internalConstructor, obj) { 56 if (internalConstructor !== diplomatRuntime.internalConstructor) { 57 throw new Error("_fromSuppliedValue cannot be called externally."); 58 } 59 60 if (obj instanceof GeneralCategoryGroup) { 61 return obj; 62 } 63 64 return GeneralCategoryGroup.fromFields(obj); 65 } 66 67 _writeToArrayBuffer( 68 arrayBuffer, 69 offset, 70 functionCleanupArena, 71 appendArrayMap 72 ) { 73 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#mask, Uint32Array); 74 } 75 76 // This struct contains borrowed fields, so this takes in a list of 77 // "edges" corresponding to where each lifetime's data may have been borrowed from 78 // and passes it down to individual fields containing the borrow. 79 // This method does not attempt to handle any dependencies between lifetimes, the caller 80 // should handle this when constructing edge arrays. 81 static _fromFFI(internalConstructor, primitiveValue) { 82 if (internalConstructor !== diplomatRuntime.internalConstructor) { 83 throw new Error("GeneralCategoryGroup._fromFFI is not meant to be called externally. Please use the default constructor."); 84 } 85 let structObj = {}; 86 structObj.mask = primitiveValue; 87 88 89 return new GeneralCategoryGroup(structObj); 90 } 91 92 contains(val) { 93 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 94 95 const result = wasm.icu4x_GeneralCategoryGroup_contains_mv1(...this._intoFFI(), val.ffiValue); 96 97 try { 98 return result; 99 } 100 101 finally { 102 functionCleanupArena.free(); 103 } 104 } 105 106 complement() { 107 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 108 109 const result = wasm.icu4x_GeneralCategoryGroup_complement_mv1(...this._intoFFI()); 110 111 try { 112 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 113 } 114 115 finally { 116 functionCleanupArena.free(); 117 } 118 } 119 120 static all() { 121 const result = wasm.icu4x_GeneralCategoryGroup_all_mv1(); 122 123 try { 124 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 125 } 126 127 finally {} 128 } 129 130 static empty() { 131 const result = wasm.icu4x_GeneralCategoryGroup_empty_mv1(); 132 133 try { 134 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 135 } 136 137 finally {} 138 } 139 140 union(other) { 141 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 142 143 const result = wasm.icu4x_GeneralCategoryGroup_union_mv1(...this._intoFFI(), ...GeneralCategoryGroup._fromSuppliedValue(diplomatRuntime.internalConstructor, other)._intoFFI(functionCleanupArena, {})); 144 145 try { 146 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 147 } 148 149 finally { 150 functionCleanupArena.free(); 151 } 152 } 153 154 intersection(other) { 155 let functionCleanupArena = new diplomatRuntime.CleanupArena(); 156 157 const result = wasm.icu4x_GeneralCategoryGroup_intersection_mv1(...this._intoFFI(), ...GeneralCategoryGroup._fromSuppliedValue(diplomatRuntime.internalConstructor, other)._intoFFI(functionCleanupArena, {})); 158 159 try { 160 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 161 } 162 163 finally { 164 functionCleanupArena.free(); 165 } 166 } 167 168 static casedLetter() { 169 const result = wasm.icu4x_GeneralCategoryGroup_cased_letter_mv1(); 170 171 try { 172 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 173 } 174 175 finally {} 176 } 177 178 static letter() { 179 const result = wasm.icu4x_GeneralCategoryGroup_letter_mv1(); 180 181 try { 182 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 183 } 184 185 finally {} 186 } 187 188 static mark() { 189 const result = wasm.icu4x_GeneralCategoryGroup_mark_mv1(); 190 191 try { 192 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 193 } 194 195 finally {} 196 } 197 198 static number() { 199 const result = wasm.icu4x_GeneralCategoryGroup_number_mv1(); 200 201 try { 202 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 203 } 204 205 finally {} 206 } 207 208 static separator() { 209 const result = wasm.icu4x_GeneralCategoryGroup_separator_mv1(); 210 211 try { 212 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 213 } 214 215 finally {} 216 } 217 218 static other() { 219 const result = wasm.icu4x_GeneralCategoryGroup_other_mv1(); 220 221 try { 222 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 223 } 224 225 finally {} 226 } 227 228 static punctuation() { 229 const result = wasm.icu4x_GeneralCategoryGroup_punctuation_mv1(); 230 231 try { 232 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 233 } 234 235 finally {} 236 } 237 238 static symbol() { 239 const result = wasm.icu4x_GeneralCategoryGroup_symbol_mv1(); 240 241 try { 242 return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result); 243 } 244 245 finally {} 246 } 247 248 constructor(structObj) { 249 return this.#internalConstructor(...arguments) 250 } 251}