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

Function classify

crates/rust/src/lib.rs:1973–2005  ·  view source on GitHub ↗
(
        resolve: &Resolve,
        resource_id: TypeId,
        result: &Option<Type>,
    )

Source from the content-addressed store, hash-verified

1971 result: &Option<Type>,
1972) -> ConstructorReturnType {
1973 fn classify(
1974 resolve: &Resolve,
1975 resource_id: TypeId,
1976 result: &Option<Type>,
1977 ) -> Option<ConstructorReturnType> {
1978 let resource_id = dealias(resolve, resource_id);
1979 let typedef = match result.as_ref()? {
1980 Type::Id(id) => &resolve.types[dealias(resolve, *id)],
1981 _ => return None,
1982 };
1983
1984 match &typedef.kind {
1985 TypeDefKind::Handle(Handle::Own(id)) if dealias(resolve, *id) == resource_id => {
1986 Some(ConstructorReturnType::Self_)
1987 }
1988 TypeDefKind::Result(Result_ { ok, err }) => {
1989 let ok_typedef = match ok.as_ref()? {
1990 Type::Id(id) => &resolve.types[dealias(resolve, *id)],
1991 _ => return None,
1992 };
1993
1994 match &ok_typedef.kind {
1995 TypeDefKind::Handle(Handle::Own(id))
1996 if dealias(resolve, *id) == resource_id =>
1997 {
1998 Some(ConstructorReturnType::Result { err: *err })
1999 }
2000 _ => None,
2001 }
2002 }
2003 _ => None,
2004 }
2005 }
2006
2007 classify(resolve, resource_id, result).expect("invalid constructor")
2008}

Callers 1

Calls 1

dealiasFunction · 0.50

Tested by

no test coverage detected