Begin deser. data structure implementation

This commit is contained in:
Amelia 2023-10-31 17:07:39 +01:00
parent 5db7f7c0d9
commit 1dac97b2dc
Signed by: limefox
GPG key ID: F86ACA6D693E7BE9
3 changed files with 51 additions and 3 deletions

1
Cargo.lock generated
View file

@ -145,6 +145,7 @@ name = "estrus"
version = "0.1.0"
dependencies = [
"reqwest",
"serde",
"tokio",
]

View file

@ -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"] }

View file

@ -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<IdentDefinition>,
/// List of references
references: Vec<IdentReference>,
/// List of positions in the documentation
documentations: Vec<IdentDocumentation>,
}
#[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::<IdentResponse>().await.expect("No failure")
}
#[tokio::main]
async fn main() {
println!("{}", find_ident("sk_buff").await)
println!("{:?}", find_ident("clear_page_erms").await)
}