From 5420e2075992711482cdece9f5d3848e581c484a Mon Sep 17 00:00:00 2001 From: Maaz Ahmed <maaz.a@subcom.tech> Date: Wed, 29 Nov 2023 16:54:58 +0530 Subject: [PATCH] chore: simple code example in README --- README.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bb5d6d1..6f02ec6 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,22 @@ # mquery (placeholder name) A Rust library for handling PROMQL (and possibly MetricsQL) queries. -# Usage Example +## Usage Example ```rust use mquery::{Auth, QueryManager}; -use tokio::runtime::Runtime; -dotenv::dotenv().expect("No .env file found in working dir"); -let url = std::env::var("VM_URL").expect("VM URL not found in env"); -let token = std::env::var("VM_TOKEN").expect("VM URL not found in env"); -let rt = Runtime::new().unwrap(); -let query = "total_http_requests"; -let _response = rt - .block_on( - QueryManager::new(url.parse().unwrap()) - .auth(Auth::Bearer(token)) - .query(query), - ) - .expect("operation failed"); +#[tokio::main] +async fn main() { + dotenv::dotenv().expect("No .env file found in working dir"); + let url = std::env::var("VM_URL").expect("VM URL not found in env"); + let token = std::env::var("VM_TOKEN").expect("VM URL not found in env"); + let query = "total_http_requests"; + + let _response = QueryManager::new(url.parse().unwrap()) + .auth(Auth::Bearer(token)) + .query(query) + .await + .expect("operation failed"); } ``` -- GitLab