Skip to main content

Info

Struct Info 

Source
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: String

Binary name (matches JSON key binary).

§version: String

Crate version from Cargo.toml (matches JSON key version).

§moduleVersion: String

Full 4-part module version (matches JSON key moduleVersion).

§maintainer: String

Maintainer contact information (matches JSON key maintainer).

§name: String

Package name (matches JSON key name).

§type: String

Module type: agent, library, executable, etc. (matches JSON key type).

§repo: String

Git repository name (matches JSON key repo).

§branch: String

Git branch name (matches JSON key branch).

§hash: String

Git commit hash (matches JSON key hash).

§copyright: String

Copyright information (matches JSON key copyright).

§os: String

Operating system name (matches JSON key os).

§osVersion: String

Operating system version (matches JSON key osVersion).

Trait Implementations§

Source§

impl Clone for Info

Source§

fn clone(&self) -> Info

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Info

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Info

Source§

fn default() -> Info

Returns the “default value” for a type. Read more
Source§

impl From<Info> for PackageMetadata

Available on Linux only.
Source§

fn from(info: Info) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Info

§

impl RefUnwindSafe for Info

§

impl Send for Info

§

impl Sync for Info

§

impl Unpin for Info

§

impl UnsafeUnpin for Info

§

impl UnwindSafe for Info

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.