Skip to main content

Sysinfo

Struct Sysinfo 

Source
pub struct Sysinfo { /* private fields */ }
Available on crate feature si only.
Expand description

The VERGEN_SYSINFO_* configuration features

VariableSample
VERGEN_SYSINFO_NAMEManjaro Linux
VERGEN_SYSINFO_OS_VERSIONLinux Manjaro Linux
VERGEN_SYSINFO_USERYoda
VERGEN_SYSINFO_TOTAL_MEMORY33 GB
VERGEN_SYSINFO_CPU_VENDORAuthentic AMD
VERGEN_SYSINFO_CPU_CORE_COUNT8
VERGEN_SYSINFO_CPU_NAMEcpu0,cpu1,cpu2,cpu3,cpu4,cpu5,cpu6,cpu7
VERGEN_SYSINFO_CPU_BRANDAMD Ryzen Threadripper 1900X 8-Core Processor
VERGEN_SYSINFO_CPU_FREQUENCY3792

§Example

Emit all sysinfo instructions

let si = Sysinfo::all_sysinfo();
Emitter::default().add_instructions(&si)?.emit()?;

Emit some of the sysinfo instructions

let si = Sysinfo::builder().os_version(true).cpu_core_count(true).build();
Emitter::default()
    .add_instructions(&si)?
    .emit()?;

Override output with your own value

temp_env::with_var("VERGEN_SYSINFO_NAME", Some("this is the name I want output"), || {
    let result = || -> Result<()> {
        let si = Sysinfo::all_sysinfo();
        Emitter::default().add_instructions(&si)?.emit()?;
        Ok(())
    }();
    assert!(result.is_ok());
});

§Example

This feature also recognizes the idempotent flag.

let si = Sysinfo::all_sysinfo();
Emitter::default().idempotent().add_instructions(&si)?.emit()?;

§Example

Use refresh_kind to minimize the amount of data that sysinfo refreshes.

let refresh_kind = RefreshKind::nothing();
let cpu_refresh_kind = CpuRefreshKind::everything()
    .without_cpu_usage()
    .without_frequency();
let si = Sysinfo::builder()
    .cpu_brand(true)
    .refresh_kind(refresh_kind.with_cpu(cpu_refresh_kind))
    .build();
let config = Emitter::default()
    .add_instructions(&si)?
    .emit()?;

The above will always generate the following output

cargo:rustc-env=VERGEN_SYSINFO_NAME=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_OS_VERSION=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_USER=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_TOTAL_MEMORY=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_CPU_VENDOR=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_CPU_CORE_COUNT=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_CPU_NAME=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_CPU_BRAND=VERGEN_IDEMPOTENT_OUTPUT
cargo:rustc-env=VERGEN_SYSINFO_CPU_FREQUENCY=VERGEN_IDEMPOTENT_OUTPUT
cargo:warning=VERGEN_SYSINFO_NAME set to default
cargo:warning=VERGEN_SYSINFO_OS_VERSION set to default
cargo:warning=VERGEN_SYSINFO_USER set to default
cargo:warning=VERGEN_SYSINFO_TOTAL_MEMORY set to default
cargo:warning=VERGEN_SYSINFO_CPU_VENDOR set to default
cargo:warning=VERGEN_SYSINFO_CPU_CORE_COUNT set to default
cargo:warning=VERGEN_SYSINFO_CPU_NAME set to default
cargo:warning=VERGEN_SYSINFO_CPU_BRAND set to default
cargo:warning=VERGEN_SYSINFO_CPU_FREQUENCY set to default
cargo:rerun-if-changed=build.rs
cargo:rerun-if-env-changed=VERGEN_IDEMPOTENT
cargo:rerun-if-env-changed=VERGEN_DEFAULT_ON_ERROR
cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH

Implementations§

Source§

impl Sysinfo

Source

pub fn builder() -> SysinfoBuilder

Create an instance of Sysinfo using the builder syntax

Source§

impl Sysinfo

Source

pub fn all_sysinfo() -> Sysinfo

Enable all of the VERGEN_SYSINFO_* options

Source

pub fn all() -> SysinfoBuilder

Convenience method to setup the Sysinfo builder with all of the VERGEN_SYSINFO_* instructions on

Trait Implementations§

Source§

impl Add for Sysinfo

Source§

fn add_map_entries( &self, idempotent: bool, cargo_rustc_env: &mut BTreeMap<VergenKey, String>, _cargo_rerun_if_changed: &mut Vec<String>, cargo_warning: &mut Vec<String>, ) -> Result<(), Error>

Try to add instructions entries to the various given arguments. Read more
Source§

fn add_default_entries( &self, _config: &DefaultConfig, _cargo_rustc_env_map: &mut BTreeMap<VergenKey, String>, _cargo_rerun_if_changed: &mut Vec<String>, _cargo_warning: &mut Vec<String>, ) -> Result<(), Error>

Based on the given configuration, emit either default idempotent output or generate a failue. Read more
Source§

impl Clone for Sysinfo

Source§

fn clone(&self) -> Sysinfo

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 Copy for Sysinfo

Source§

impl Debug for Sysinfo

Source§

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

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

impl PartialEq for Sysinfo

Source§

fn eq(&self, other: &Sysinfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Sysinfo

Auto Trait Implementations§

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.