Skip to content

defineCargoPolicy

defineCargoPolicy<C>(args): PolicyShape<C>

Defined in: policyDefiners/defineCargoPolicy.ts:99

Define a repo policy for Cargo.toml files.

C = undefined

DefineCargoPolicyArgs<C>

Policy metadata, parsed-TOML handler, and optional defaults.

PolicyShape<C>

A file policy that reads and parses matching Cargo.toml files.

This is a helper function that creates a policy pre-configured to match Cargo.toml files. The handler receives the parsed TOML content.

const MyCargoPolicy = defineCargoPolicy({
name: "MyCargoPolicy",
description: "Ensures Cargo.toml has required fields",
handler: async (toml, { file }) => {
const pkg = toml.package as Record<string, unknown> | undefined;
if (!pkg?.name) {
return { error: "Missing package name", fixable: false };
}
return true;
},
});