Returns the "default export" of a module. An export with an empty string is considered to be a "default export". "_start" is also recognized for compatibility. # Panics Panics if the default function found is not owned by `store`. This function will also panic if the `store` provided does not come from the same [`Engine`] that this linker was created with. # Errors This function will return a
(&self, mut store: impl AsContextMut<Data = T>, module: &str)
| 1379 | /// memory allocation fails. See the `OutOfMemory` type's documentation for |
| 1380 | /// details on Wasmtime's out-of-memory handling. |
| 1381 | pub fn get_default(&self, mut store: impl AsContextMut<Data = T>, module: &str) -> Result<Func> |
| 1382 | where |
| 1383 | T: 'static, |
| 1384 | { |
| 1385 | if let Some(external) = self.get(&mut store, module, "").map(Some).or_else(|e| { |
| 1386 | if e.is::<OutOfMemory>() { |
| 1387 | Err(e) |
| 1388 | } else { |
| 1389 | Ok(None) |
| 1390 | } |
| 1391 | })? { |
| 1392 | if let Extern::Func(func) = external { |
| 1393 | return Ok(func); |
| 1394 | } |
| 1395 | bail!("default export in '{module}' is not a function"); |
| 1396 | } |
| 1397 | |
| 1398 | // For compatibility, also recognize "_start". |
| 1399 | if let Some(external) = self |
| 1400 | .get(&mut store, module, "_start") |
| 1401 | .map(Some) |
| 1402 | .or_else(|e| { |
| 1403 | if e.is::<OutOfMemory>() { |
| 1404 | Err(e) |
| 1405 | } else { |
| 1406 | Ok(None) |
| 1407 | } |
| 1408 | })? |
| 1409 | { |
| 1410 | if let Extern::Func(func) = external { |
| 1411 | return Ok(func); |
| 1412 | } |
| 1413 | bail!("`_start` in '{module}' is not a function"); |
| 1414 | } |
| 1415 | |
| 1416 | // Otherwise return a no-op function. |
| 1417 | Ok(Func::wrap(store, || {})) |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | impl<T: 'static> Default for Linker<T> { |