To get the system total disk space in Rust, we can use the sys-info
crate. This crate provides a convenient way to retrieve system information, including disk capacity.
Here is an example Rust code snippet that prints the total capacity of the system's primary disk:
main.rs417 chars14 lines
In this code, we first use sys_info::system_info()
to obtain a System
struct that holds various system information. We then use system.get_disks().first().unwrap().get_name()
to get the name of the primary disk. Finally, we use system.get_total_disk_space(primary_disk_name).unwrap()
to get the total capacity of the primary disk in bytes.
gistlibby LogSnag