MCPcopy Create free account
hub / github.com/bytecodealliance/cargo-component / validate_component

Function validate_component

tests/support/mod.rs:390–413  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

388}
389
390pub fn validate_component(path: &Path) -> Result<()> {
391 let bytes = fs::read(path)
392 .with_context(|| format!("failed to read `{path}`", path = path.display()))?;
393
394 // Validate the bytes as either a component or a module
395 Validator::new_with_features(Default::default()).validate_all(&bytes)?;
396
397 // Check that the bytes are for a component and not a module
398 let mut parser = Parser::new(0);
399 match parser.parse(&bytes, true)? {
400 Chunk::Parsed {
401 payload:
402 Payload::Version {
403 encoding: Encoding::Component,
404 ..
405 },
406 ..
407 } => Ok(()),
408 Chunk::Parsed { payload, .. } => {
409 bail!("expected component version payload, got {:?}", payload)
410 }
411 Chunk::NeedMoreData(_) => unreachable!(),
412 }
413}

Calls 1

parseMethod · 0.80