mirror of
https://git.vulpinecitrus.info/Lymkwi/estrus-navigator.git
synced 2024-11-25 03:26:36 +00:00
Begin deser. data structure implementation
This commit is contained in:
parent
5db7f7c0d9
commit
1dac97b2dc
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -145,6 +145,7 @@ name = "estrus"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
|
@ -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"] }
|
||||
|
|
52
src/main.rs
52
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<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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue