github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library@v0.2.0/Wrappers/Wrappers.go (about) 1 // Package Wrappers 2 // Dafny module Wrappers compiled into Go 3 4 package Wrappers 5 6 import ( 7 os "os" 8 9 m__System "github.com/dafny-lang/DafnyRuntimeGo/v4/System_" 10 _dafny "github.com/dafny-lang/DafnyRuntimeGo/v4/dafny" 11 ) 12 13 var _ = os.Args 14 var _ _dafny.Dummy__ 15 var _ m__System.Dummy__ 16 17 type Dummy__ struct{} 18 19 // Definition of class Default__ 20 type Default__ struct { 21 dummy byte 22 } 23 24 func New_Default___() *Default__ { 25 _this := Default__{} 26 27 return &_this 28 } 29 30 type CompanionStruct_Default___ struct { 31 } 32 33 var Companion_Default___ = CompanionStruct_Default___{} 34 35 func (_this *Default__) Equals(other *Default__) bool { 36 return _this == other 37 } 38 39 func (_this *Default__) EqualsGeneric(x interface{}) bool { 40 other, ok := x.(*Default__) 41 return ok && _this.Equals(other) 42 } 43 44 func (*Default__) String() string { 45 return "Wrappers.Default__" 46 } 47 func (_this *Default__) ParentTraits_() []*_dafny.TraitID { 48 return [](*_dafny.TraitID){} 49 } 50 51 var _ _dafny.TraitOffspring = &Default__{} 52 53 func (_static *CompanionStruct_Default___) Need(condition bool, error_ interface{}) Outcome { 54 if condition { 55 return Companion_Outcome_.Create_Pass_() 56 } else { 57 return Companion_Outcome_.Create_Fail_(error_) 58 } 59 } 60 61 // End of class Default__ 62 63 // Definition of datatype Option 64 type Option struct { 65 Data_Option_ 66 } 67 68 func (_this Option) Get_() Data_Option_ { 69 return _this.Data_Option_ 70 } 71 72 type Data_Option_ interface { 73 isOption() 74 } 75 76 type CompanionStruct_Option_ struct { 77 } 78 79 var Companion_Option_ = CompanionStruct_Option_{} 80 81 type Option_None struct { 82 } 83 84 func (Option_None) isOption() {} 85 86 func (CompanionStruct_Option_) Create_None_() Option { 87 return Option{Option_None{}} 88 } 89 90 func (_this Option) Is_None() bool { 91 _, ok := _this.Get_().(Option_None) 92 return ok 93 } 94 95 type Option_Some struct { 96 Value interface{} 97 } 98 99 func (Option_Some) isOption() {} 100 101 func (CompanionStruct_Option_) Create_Some_(Value interface{}) Option { 102 return Option{Option_Some{Value}} 103 } 104 105 func (_this Option) Is_Some() bool { 106 _, ok := _this.Get_().(Option_Some) 107 return ok 108 } 109 110 func (CompanionStruct_Option_) Default() Option { 111 return Companion_Option_.Create_None_() 112 } 113 114 func (_this Option) Dtor_value() interface{} { 115 return _this.Get_().(Option_Some).Value 116 } 117 118 func (_this Option) String() string { 119 switch data := _this.Get_().(type) { 120 case nil: 121 return "null" 122 case Option_None: 123 { 124 return "Wrappers.Option.None" 125 } 126 case Option_Some: 127 { 128 return "Wrappers.Option.Some" + "(" + _dafny.String(data.Value) + ")" 129 } 130 default: 131 { 132 return "<unexpected>" 133 } 134 } 135 } 136 137 func (_this Option) Equals(other Option) bool { 138 switch data1 := _this.Get_().(type) { 139 case Option_None: 140 { 141 _, ok := other.Get_().(Option_None) 142 return ok 143 } 144 case Option_Some: 145 { 146 data2, ok := other.Get_().(Option_Some) 147 return ok && _dafny.AreEqual(data1.Value, data2.Value) 148 } 149 default: 150 { 151 return false // unexpected 152 } 153 } 154 } 155 156 func (_this Option) EqualsGeneric(other interface{}) bool { 157 typed, ok := other.(Option) 158 return ok && _this.Equals(typed) 159 } 160 161 func Type_Option_() _dafny.TypeDescriptor { 162 return type_Option_{} 163 } 164 165 type type_Option_ struct { 166 } 167 168 func (_this type_Option_) Default() interface{} { 169 return Companion_Option_.Default() 170 } 171 172 func (_this type_Option_) String() string { 173 return "Wrappers.Option" 174 } 175 func (_this Option) ParentTraits_() []*_dafny.TraitID { 176 return [](*_dafny.TraitID){} 177 } 178 179 var _ _dafny.TraitOffspring = Option{} 180 181 func (_this Option) ToResult() Result { 182 { 183 var _source0 Option = _this 184 _ = _source0 185 { 186 if _source0.Is_Some() { 187 var _0_v interface{} = _source0.Get_().(Option_Some).Value 188 _ = _0_v 189 return Companion_Result_.Create_Success_(_0_v) 190 } 191 } 192 { 193 return Companion_Result_.Create_Failure_(_dafny.SeqOfString("Option is None")) 194 } 195 } 196 } 197 func (_this Option) ToResult_k(error_ interface{}) Result { 198 { 199 var _source0 Option = _this 200 _ = _source0 201 { 202 if _source0.Is_Some() { 203 var _0_v interface{} = _source0.Get_().(Option_Some).Value 204 _ = _0_v 205 return Companion_Result_.Create_Success_(_0_v) 206 } 207 } 208 { 209 return Companion_Result_.Create_Failure_(error_) 210 } 211 } 212 } 213 func (_this Option) UnwrapOr(default_ interface{}) interface{} { 214 { 215 var _source0 Option = _this 216 _ = _source0 217 { 218 if _source0.Is_Some() { 219 var _0_v interface{} = _source0.Get_().(Option_Some).Value 220 _ = _0_v 221 return _0_v 222 } 223 } 224 { 225 return default_ 226 } 227 } 228 } 229 func (_this Option) IsFailure() bool { 230 { 231 return (_this).Is_None() 232 } 233 } 234 func (_this Option) PropagateFailure() Option { 235 { 236 return Companion_Option_.Create_None_() 237 } 238 } 239 func (_this Option) Extract() interface{} { 240 { 241 return (_this).Dtor_value() 242 } 243 } 244 245 // End of datatype Option 246 247 // Definition of datatype Result 248 type Result struct { 249 Data_Result_ 250 } 251 252 func (_this Result) Get_() Data_Result_ { 253 return _this.Data_Result_ 254 } 255 256 type Data_Result_ interface { 257 isResult() 258 } 259 260 type CompanionStruct_Result_ struct { 261 } 262 263 var Companion_Result_ = CompanionStruct_Result_{} 264 265 type Result_Success struct { 266 Value interface{} 267 } 268 269 func (Result_Success) isResult() {} 270 271 func (CompanionStruct_Result_) Create_Success_(Value interface{}) Result { 272 return Result{Result_Success{Value}} 273 } 274 275 func (_this Result) Is_Success() bool { 276 _, ok := _this.Get_().(Result_Success) 277 return ok 278 } 279 280 type Result_Failure struct { 281 Error interface{} 282 } 283 284 func (Result_Failure) isResult() {} 285 286 func (CompanionStruct_Result_) Create_Failure_(Error interface{}) Result { 287 return Result{Result_Failure{Error}} 288 } 289 290 func (_this Result) Is_Failure() bool { 291 _, ok := _this.Get_().(Result_Failure) 292 return ok 293 } 294 295 func (CompanionStruct_Result_) Default(_default_T interface{}) Result { 296 return Companion_Result_.Create_Success_(_default_T) 297 } 298 299 func (_this Result) Dtor_value() interface{} { 300 return _this.Get_().(Result_Success).Value 301 } 302 303 func (_this Result) Dtor_error() interface{} { 304 return _this.Get_().(Result_Failure).Error 305 } 306 307 func (_this Result) String() string { 308 switch data := _this.Get_().(type) { 309 case nil: 310 return "null" 311 case Result_Success: 312 { 313 return "Wrappers.Result.Success" + "(" + _dafny.String(data.Value) + ")" 314 } 315 case Result_Failure: 316 { 317 return "Wrappers.Result.Failure" + "(" + _dafny.String(data.Error) + ")" 318 } 319 default: 320 { 321 return "<unexpected>" 322 } 323 } 324 } 325 326 func (_this Result) Equals(other Result) bool { 327 switch data1 := _this.Get_().(type) { 328 case Result_Success: 329 { 330 data2, ok := other.Get_().(Result_Success) 331 return ok && _dafny.AreEqual(data1.Value, data2.Value) 332 } 333 case Result_Failure: 334 { 335 data2, ok := other.Get_().(Result_Failure) 336 return ok && _dafny.AreEqual(data1.Error, data2.Error) 337 } 338 default: 339 { 340 return false // unexpected 341 } 342 } 343 } 344 345 func (_this Result) EqualsGeneric(other interface{}) bool { 346 typed, ok := other.(Result) 347 return ok && _this.Equals(typed) 348 } 349 350 func Type_Result_(Type_T_ _dafny.TypeDescriptor) _dafny.TypeDescriptor { 351 return type_Result_{Type_T_} 352 } 353 354 type type_Result_ struct { 355 Type_T_ _dafny.TypeDescriptor 356 } 357 358 func (_this type_Result_) Default() interface{} { 359 Type_T_ := _this.Type_T_ 360 _ = Type_T_ 361 return Companion_Result_.Default(Type_T_.Default()) 362 } 363 364 func (_this type_Result_) String() string { 365 return "Wrappers.Result" 366 } 367 func (_this Result) ParentTraits_() []*_dafny.TraitID { 368 return [](*_dafny.TraitID){} 369 } 370 371 var _ _dafny.TraitOffspring = Result{} 372 373 func (_this Result) ToOption() Option { 374 { 375 var _source0 Result = _this 376 _ = _source0 377 { 378 if _source0.Is_Success() { 379 var _0_s interface{} = _source0.Get_().(Result_Success).Value 380 _ = _0_s 381 return Companion_Option_.Create_Some_(_0_s) 382 } 383 } 384 { 385 var _1_e interface{} = _source0.Get_().(Result_Failure).Error 386 _ = _1_e 387 return Companion_Option_.Create_None_() 388 } 389 } 390 } 391 func (_this Result) UnwrapOr(default_ interface{}) interface{} { 392 { 393 var _source0 Result = _this 394 _ = _source0 395 { 396 if _source0.Is_Success() { 397 var _0_s interface{} = _source0.Get_().(Result_Success).Value 398 _ = _0_s 399 return _0_s 400 } 401 } 402 { 403 var _1_e interface{} = _source0.Get_().(Result_Failure).Error 404 _ = _1_e 405 return default_ 406 } 407 } 408 } 409 func (_this Result) IsFailure() bool { 410 { 411 return (_this).Is_Failure() 412 } 413 } 414 func (_this Result) PropagateFailure() Result { 415 { 416 return Companion_Result_.Create_Failure_((_this).Dtor_error()) 417 } 418 } 419 func (_this Result) MapFailure(reWrap func(interface{}) interface{}) Result { 420 { 421 var _source0 Result = _this 422 _ = _source0 423 { 424 if _source0.Is_Success() { 425 var _0_s interface{} = _source0.Get_().(Result_Success).Value 426 _ = _0_s 427 return Companion_Result_.Create_Success_(_0_s) 428 } 429 } 430 { 431 var _1_e interface{} = _source0.Get_().(Result_Failure).Error 432 _ = _1_e 433 return Companion_Result_.Create_Failure_((reWrap)(_1_e)) 434 } 435 } 436 } 437 func (_this Result) Extract() interface{} { 438 { 439 return (_this).Dtor_value() 440 } 441 } 442 443 // End of datatype Result 444 445 // Definition of datatype Outcome 446 type Outcome struct { 447 Data_Outcome_ 448 } 449 450 func (_this Outcome) Get_() Data_Outcome_ { 451 return _this.Data_Outcome_ 452 } 453 454 type Data_Outcome_ interface { 455 isOutcome() 456 } 457 458 type CompanionStruct_Outcome_ struct { 459 } 460 461 var Companion_Outcome_ = CompanionStruct_Outcome_{} 462 463 type Outcome_Pass struct { 464 } 465 466 func (Outcome_Pass) isOutcome() {} 467 468 func (CompanionStruct_Outcome_) Create_Pass_() Outcome { 469 return Outcome{Outcome_Pass{}} 470 } 471 472 func (_this Outcome) Is_Pass() bool { 473 _, ok := _this.Get_().(Outcome_Pass) 474 return ok 475 } 476 477 type Outcome_Fail struct { 478 Error interface{} 479 } 480 481 func (Outcome_Fail) isOutcome() {} 482 483 func (CompanionStruct_Outcome_) Create_Fail_(Error interface{}) Outcome { 484 return Outcome{Outcome_Fail{Error}} 485 } 486 487 func (_this Outcome) Is_Fail() bool { 488 _, ok := _this.Get_().(Outcome_Fail) 489 return ok 490 } 491 492 func (CompanionStruct_Outcome_) Default() Outcome { 493 return Companion_Outcome_.Create_Pass_() 494 } 495 496 func (_this Outcome) Dtor_error() interface{} { 497 return _this.Get_().(Outcome_Fail).Error 498 } 499 500 func (_this Outcome) String() string { 501 switch data := _this.Get_().(type) { 502 case nil: 503 return "null" 504 case Outcome_Pass: 505 { 506 return "Wrappers.Outcome.Pass" 507 } 508 case Outcome_Fail: 509 { 510 return "Wrappers.Outcome.Fail" + "(" + _dafny.String(data.Error) + ")" 511 } 512 default: 513 { 514 return "<unexpected>" 515 } 516 } 517 } 518 519 func (_this Outcome) Equals(other Outcome) bool { 520 switch data1 := _this.Get_().(type) { 521 case Outcome_Pass: 522 { 523 _, ok := other.Get_().(Outcome_Pass) 524 return ok 525 } 526 case Outcome_Fail: 527 { 528 data2, ok := other.Get_().(Outcome_Fail) 529 return ok && _dafny.AreEqual(data1.Error, data2.Error) 530 } 531 default: 532 { 533 return false // unexpected 534 } 535 } 536 } 537 538 func (_this Outcome) EqualsGeneric(other interface{}) bool { 539 typed, ok := other.(Outcome) 540 return ok && _this.Equals(typed) 541 } 542 543 func Type_Outcome_() _dafny.TypeDescriptor { 544 return type_Outcome_{} 545 } 546 547 type type_Outcome_ struct { 548 } 549 550 func (_this type_Outcome_) Default() interface{} { 551 return Companion_Outcome_.Default() 552 } 553 554 func (_this type_Outcome_) String() string { 555 return "Wrappers.Outcome" 556 } 557 func (_this Outcome) ParentTraits_() []*_dafny.TraitID { 558 return [](*_dafny.TraitID){} 559 } 560 561 var _ _dafny.TraitOffspring = Outcome{} 562 563 func (_this Outcome) IsFailure() bool { 564 { 565 return (_this).Is_Fail() 566 } 567 } 568 func (_this Outcome) PropagateFailure() Result { 569 { 570 return Companion_Result_.Create_Failure_((_this).Dtor_error()) 571 } 572 } 573 574 // End of datatype Outcome