pub struct Info {
pub binary: String,
pub version: String,
pub moduleVersion: String,
pub maintainer: String,
pub name: String,
pub type: String,
pub repo: String,
pub branch: String,
pub hash: String,
pub copyright: String,
pub os: String,
pub osVersion: String,
}Expand description
Convenience struct-literal view over PackageMetadata with field names
shaped like the JSON keys rather than the internal Rust snake_case names.
Info exists so call sites can read the same way the embedded JSON reads:
r#type, moduleVersion, osVersion instead of module_type,
module_version, os_version. It’s deliberately not #[non_exhaustive]:
struct-literal construction is the whole point. Pass it to new to build
the note artifacts in one call:
§Forward compatibility
Always terminate the struct literal with ..Default::default(). Unlike
PackageMetadata (which is #[non_exhaustive] and forbids struct-literal
construction from outside the crate, forcing consumers into the
field-assignment pattern that is intrinsically forward-compatible), Info
permits a fully-exhaustive literal. That means a minor release of this
crate that adds a new field will break any Info { … } call site that
listed every field by name. The ..Default::default() terminator is how
consumers buy forward compatibility: new fields fall back to their
Default value (empty string / disabled) instead of failing to compile.
This is the only reason Info is safe to add fields to in minor
releases. Omit the terminator and the crate can no longer do that
without breaking you.
let _ = module_info::new(Info {
binary: "my_tool".into(),
name: "my_tool".into(),
maintainer: "team@contoso.com".into(),
version: "1.2.3".into(),
moduleVersion: "1.2.3.4".into(),
os: "linux".into(),
osVersion: "22.04".into(),
r#type: "agent".into(),
hash: "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".into(),
..Default::default()
});Under the hood new converts this to a PackageMetadata and calls
embed_package_metadata with EmbedOptions::default().
§No auto-detection on this path
Every field in the Info literal ships verbatim. os/osVersion are
not read from /etc/os-release, and repo/branch/hash are
not read from git. The caller owns every value. If you want the
/etc/os-release + git auto-detection that the zero-config entry point
provides, reach for PackageMetadata::from_cargo_toml instead,
mutate the fields you want to override, and pass the result to
embed_package_metadata.
§Disabling fields
Seven keys are required at validation time:
binary, version, moduleVersion, name, maintainer, os, and
osVersion. The rest (r#type, repo, branch, hash, copyright)
may be left as the empty string (the Default value);
..Default::default() in the literal above is the idiomatic way to
opt out. The embedded JSON still carries every key (the
.note.package layout is fixed), but the value ships as "", which
downstream tooling can treat as “disabled.”
§r#type tradeoff
The JSON key is type, which collides with Rust’s type keyword. We use
the raw-identifier form r#type rather than a #[serde(rename = "type")]
alias on a differently-named field (say, module_type), because the
latter would require call sites to remember the rename when constructing
the struct literal, re-creating the original mismatch this type is meant
to solve. r#type is ugly but pays off once: downstream construction
reads r#type: "agent".into() and the JSON reads "type":"agent".
Fields§
§binary: StringBinary name (matches JSON key binary).
version: StringCrate version from Cargo.toml (matches JSON key version).
moduleVersion: StringFull 4-part module version (matches JSON key moduleVersion).
maintainer: StringMaintainer contact information (matches JSON key maintainer).
name: StringPackage name (matches JSON key name).
type: StringModule type: agent, library, executable, etc. (matches JSON key type).
repo: StringGit repository name (matches JSON key repo).
branch: StringGit branch name (matches JSON key branch).
hash: StringGit commit hash (matches JSON key hash).
copyright: StringCopyright information (matches JSON key copyright).
os: StringOperating system name (matches JSON key os).
osVersion: StringOperating system version (matches JSON key osVersion).