Structure used to represent either a `Trap` or an `Error`.
| 151 | |
| 152 | /// Structure used to represent either a `Trap` or an `Error`. |
| 153 | struct TrapError { |
| 154 | /// Storage for what this trap represents. |
| 155 | std::variant<Trap, Error> data; |
| 156 | |
| 157 | /// Creates a new `TrapError` from a `Trap` |
| 158 | TrapError(Trap t) : data(std::move(t)) {} |
| 159 | /// Creates a new `TrapError` from an `Error` |
| 160 | TrapError(Error e) : data(std::move(e)) {} |
| 161 | |
| 162 | /// Dispatches internally to return the message associated with this error. |
| 163 | std::string message() const { |
| 164 | if (const auto *trap = std::get_if<Trap>(&data)) { |
| 165 | return trap->message(); |
| 166 | } |
| 167 | if (const auto *error = std::get_if<Error>(&data)) { |
| 168 | return std::string(error->message()); |
| 169 | } |
| 170 | std::abort(); |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | /// Result used by functions which can fail because of invariants being violated |
| 175 | /// (such as a type error) as well as because of a WebAssembly trap. |
no outgoing calls
no test coverage detected