Fork me on GitHub
#other-languages
<
2020-02-25
>
borkdude14:02:40

I'm trying to write a very simple Rust program that gets me the amount of free memory on my system. I'm using the heim create. How do I get this to compile?

use heim::memory as memory;
use heim::units::information;

async fn get_mem() -> u64 {
    let mem = memory::memory().await.unwrap();
    mem.free().get::<information::megabyte>()
}

async fn main() -> Result<()> {
    let free = get_mem().await;
    println!("Free memory: {}", free);
}
I know it's pretty bad to call .unwrap() like this, but I'm just trying ...

borkdude14:02:34

This is the current output:

$ cargo run
   Compiling heimtry v0.1.0 (/Users/borkdude/Dropbox/dev/rust/heimtry)
error[E0107]: wrong number of type arguments: expected 2, found 1
 --> src/main.rs:9:20
  |
9 | async fn main() -> Result<()> {
  |                    ^^^^^^^^^^ expected 2 type arguments

error[E0277]: `main` has invalid return type `impl std::future::Future`
 --> src/main.rs:9:20
  |
9 | async fn main() -> Result<()> {
  |                    ^^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
  |
  = help: consider using `()`, or a `Result
`

borkdude14:02:54

[dependencies]
heim = "0.0.10"

gklijs14:02:35

I think the main itself should not be async, but I still have to read up on async, https://rust-lang.github.io/async-book/

gklijs15:02:19

I just briefly used async because the kafka client started using them a lot, till I found out it wasn't supported in tests, so did it some other way. It's not that long in stable, so could be error messages could be improved.

borkdude15:02:32

I guess I need to block on something, but don't know how. I'll keep reading the book 😉