MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / is_fallible_constructor

Method is_fallible_constructor

crates/cpp/src/lib.rs:305–314  ·  view source on GitHub ↗

Returns true if the function is a fallible constructor. Fallible constructors are constructors that return `result ` instead of just `T`. In the generated C++ code, these become static factory methods named `Create` that return `std::expected `, rather than regular constructors.

(&self, resolve: &Resolve, func: &Function)

Source from the content-addressed store, hash-verified

303 /// In the generated C++ code, these become static factory methods named `Create` that
304 /// return `std::expected<T, E>`, rather than regular constructors.
305 fn is_fallible_constructor(&self, resolve: &Resolve, func: &Function) -> bool {
306 matches!(&func.kind, FunctionKind::Constructor(_))
307 && func.result.as_ref().is_some_and(|ty| {
308 if let Type::Id(id) = ty {
309 matches!(&resolve.types[*id].kind, TypeDefKind::Result(_))
310 } else {
311 false
312 }
313 })
314 }
315
316 fn interface<'a>(
317 &'a mut self,

Callers 4

func_namespace_nameMethod · 0.80
high_level_signatureMethod · 0.80
type_resourceMethod · 0.80
emitMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected