From 1dac97b2dcbafcb22f344ae66f932ee94382c93b Mon Sep 17 00:00:00 2001 From: Lymkwi Date: Tue, 31 Oct 2023 17:07:39 +0100 Subject: [PATCH] Begin deser. data structure implementation --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a780362..6c7642d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,7 @@ name = "estrus" version = "0.1.0" dependencies = [ "reqwest", + "serde", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index bd7f85e..37458b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ license = "ACSL" [dependencies] reqwest = { version = "0.11.22", features = ["default-tls", "json", "gzip"] } +serde = { version = "1.0.190", features = ["derive"] } tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros", "net"] } diff --git a/src/main.rs b/src/main.rs index 9a09241..a8a0abe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,60 @@ +//! Main module for the project +//! + +use std::path::PathBuf; + use reqwest::Client; -async fn find_ident(ident: &str) -> String { +/// Response to an Ident query on the Elixir API +/// +/// Holds the deserialized response to a query to the elixir API regarding definitions, references, +/// and documentation of an identifier. +#[derive(serde::Deserialize, Debug)] +struct IdentResponse { + /// List of definitions + definitions: Vec, + /// List of references + references: Vec, + /// List of positions in the documentation + documentations: Vec, +} + +#[derive(serde::Deserialize, Debug)] +/// Different possible types of Identifier Definitions +enum IdentDefinitionType { + Prototype, +} + +#[derive(serde::Deserialize, Debug)] +struct IdentDefinition { + path: PathBuf, + line: u32, + deftype: IdentDefinitionType, +} + +#[derive(serde::Deserialize, Debug)] +struct IdentReference { + path: PathBuf, + line: u32, + reftype: Option<()> +} + +#[derive(serde::Deserialize, Debug)] +struct IdentDocumentation { + path: PathBuf, + line: u32, + doctype: Option<()> +} + +async fn find_ident(ident: &str) -> IdentResponse { let client = Client::new(); let res = client.get(format!("https://elixir.bootlin.com/api/ident/linux/{ident}?version=latest")) .send() .await.expect("No future failure"); - res.text().await.expect("Valid text sent") + res.json::().await.expect("No failure") } #[tokio::main] async fn main() { - println!("{}", find_ident("sk_buff").await) + println!("{:?}", find_ident("clear_page_erms").await) }