Crates.io | apollo-environment-detector |
lib.rs | apollo-environment-detector |
version | 0.1.0 |
source | src |
created_at | 2024-10-31 11:47:17.26877 |
updated_at | 2024-10-31 11:47:17.26877 |
description | Library for detecting different compute environments |
homepage | |
repository | https://github.com/apollographql/environment-detector |
max_upload_size | |
id | 1429925 |
size | 51,088 |
This library provides two functions for easily detecting a ComputeEnvironment
based on a
given weighted threshold.
[dependencies]
apollo-environment-detector = "0.1"
use apollo_environment_detector::{detect, detect_one, MAX_INDIVIDUAL_WEIGHTING};
// Attempt to detect multiple environments based on a weighting.
let compute_envs = detect(MAX_INDIVIDUAL_WEIGHTING);
println!("{:?}", compute_envs);
// Attempt to detect a single environment based on a weighting.
let compute_env = detect_one(MAX_INDIVIDUAL_WEIGHTING);
println!("{:?}", compute_env);
The following environments are able to be detected:
This library currently supports 2 detection methods: SMBIOS and Environment Variables.
There are currently 3 data points read during detection on both Linux and Windows:
bios_vendor
product_name
sys_vendor
A detection threshold is represented in the form of a u16
, which has a max of 65535
(2^16-1
) as defined in u16::MAX
.
As we supported multiple detectors, the maximum returned total weighting is 2^15
in order to avoid thresholding and overflows when using multiple detectors. This is exposed as a constant MAX_TOTAL_WEIGHTING
.