Fix warnings

This commit is contained in:
Joel Wachsler 2022-07-22 14:34:47 +00:00
parent 68bb159dc3
commit 07e825bcd4
5 changed files with 11 additions and 476 deletions

File diff suppressed because it is too large Load Diff

View File

@ -127,10 +127,6 @@ impl parser::ApiMethod {
}
}
fn name_camel(&self) -> Ident {
util::to_ident(&self.name.to_camel())
}
fn name_snake(&self) -> Ident {
util::to_ident(&self.name.to_snake())
}
@ -169,10 +165,6 @@ impl types::Type {
self.get_type_info().name.clone()
}
fn name_camel(&self) -> Ident {
util::to_ident(&self.name().to_camel())
}
fn name_snake(&self) -> Ident {
util::to_ident(&self.name().to_snake())
}
@ -218,10 +210,6 @@ impl parser::EnumValue {
fn name_camel(&self) -> Ident {
util::to_ident(&self.value.to_camel())
}
fn name_snake(&self) -> Ident {
util::to_ident(&self.value.to_snake())
}
}
#[derive(Debug)]

View File

@ -13,33 +13,27 @@ ApiMethod {
TypeInfo {
name: "id",
is_optional: false,
is_list: false,
description: Some(
"ID of the search job",
),
type_description: None,
},
),
Number(
TypeInfo {
name: "limit",
is_optional: true,
is_list: false,
description: Some(
"max number of results to return. 0 or negative means no limit",
),
type_description: None,
},
),
Number(
TypeInfo {
name: "offset",
is_optional: true,
is_list: false,
description: Some(
"result to start at. A negative number means count backwards (e.g. -2 returns the 2 most recent results)",
),
type_description: None,
},
),
],
@ -53,77 +47,63 @@ ApiMethod {
TypeInfo {
name: "descrLink",
is_optional: false,
is_list: false,
description: Some(
"URL of the torrent's description page",
),
type_description: None,
},
),
String(
TypeInfo {
name: "fileName",
is_optional: false,
is_list: false,
description: Some(
"Name of the file",
),
type_description: None,
},
),
Number(
TypeInfo {
name: "fileSize",
is_optional: false,
is_list: false,
description: Some(
"Size of the file in Bytes",
),
type_description: None,
},
),
String(
TypeInfo {
name: "fileUrl",
is_optional: false,
is_list: false,
description: Some(
"Torrent download link (usually either .torrent file or magnet link)",
),
type_description: None,
},
),
Number(
TypeInfo {
name: "nbLeechers",
is_optional: false,
is_list: false,
description: Some(
"Number of leechers",
),
type_description: None,
},
),
Number(
TypeInfo {
name: "nbSeeders",
is_optional: false,
is_list: false,
description: Some(
"Number of seeders",
),
type_description: None,
},
),
String(
TypeInfo {
name: "siteUrl",
is_optional: false,
is_list: false,
description: Some(
"URL of the torrent site",
),
type_description: None,
},
),
],
@ -137,11 +117,9 @@ ApiMethod {
type_info: TypeInfo {
name: "results",
is_optional: false,
is_list: false,
description: Some(
"Array of result objects- see table below",
),
type_description: None,
},
ref_type: "Result",
},
@ -150,22 +128,18 @@ ApiMethod {
TypeInfo {
name: "status",
is_optional: false,
is_list: false,
description: Some(
"Current status of the search job (either Running or Stopped)",
),
type_description: None,
},
),
Number(
TypeInfo {
name: "total",
is_optional: false,
is_list: false,
description: Some(
"Total number of results. If the status is Running this number may continue to increase",
),
type_description: None,
},
),
],

View File

@ -5,7 +5,7 @@ mod url;
use crate::{md_parser, types};
use case::CaseExt;
use regex::Regex;
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
#[derive(Debug)]
pub struct ApiMethod {
@ -312,13 +312,6 @@ impl md_parser::Table {
impl md_parser::TableRow {
fn to_type(&self) -> Option<types::Type> {
self.to_types_with_types(&HashMap::new())
}
fn to_types_with_types(
&self,
type_map: &HashMap<String, types::TypeDescription>,
) -> Option<types::Type> {
let columns = &self.columns;
let description = columns.get(2).cloned();
@ -327,9 +320,9 @@ impl md_parser::TableRow {
Some(desc) if desc.contains("default: ") => {
// type defines a variable as default if it contains: _optional_
let name_with_optional = format!("{} {}", columns[0], types::OPTIONAL);
types::Type::from(&columns[1], &name_with_optional, description, type_map)
types::Type::from(&columns[1], &name_with_optional, description)
}
_ => types::Type::from(&columns[1], &columns[0], description, type_map),
_ => types::Type::from(&columns[1], &columns[0], description),
}
}
}

View File

@ -1,5 +1,3 @@
use std::collections::HashMap;
use case::CaseExt;
use regex::RegexBuilder;
@ -18,25 +16,17 @@ pub struct TypeDescription {
pub struct TypeInfo {
pub name: String,
pub is_optional: bool,
is_list: bool,
// is_list: bool,
pub description: Option<String>,
pub type_description: Option<TypeDescription>,
}
impl TypeInfo {
pub fn new(
name: &str,
is_optional: bool,
is_list: bool,
description: Option<String>,
type_description: Option<TypeDescription>,
) -> Self {
pub fn new(name: &str, is_optional: bool, description: Option<String>) -> Self {
Self {
name: name.into(),
is_optional,
is_list,
// is_list,
description,
type_description,
}
}
}
@ -84,9 +74,9 @@ impl Type {
}
}
pub fn is_list(&self) -> bool {
self.get_type_info().is_list || matches!(self, Type::StringArray(_))
}
// pub fn is_list(&self) -> bool {
// self.get_type_info().is_list || matches!(self, Type::StringArray(_))
// }
pub fn to_borrowed_type(&self) -> String {
match self {
@ -118,13 +108,7 @@ impl Type {
}
}
pub fn from(
type_as_str: &str,
name: &str,
description: Option<String>,
types: &HashMap<String, TypeDescription>,
) -> Option<Type> {
let available_types = types.get(name).cloned();
pub fn from(type_as_str: &str, name: &str, description: Option<String>) -> Option<Type> {
let type_name = match name.split_once(OPTIONAL) {
Some((split, _)) => split,
None => name,
@ -132,15 +116,7 @@ impl Type {
.trim();
let is_optional = name.contains(OPTIONAL);
let create_type_info = || {
TypeInfo::new(
type_name,
is_optional,
false,
description.clone(),
available_types.clone(),
)
};
let create_type_info = || TypeInfo::new(type_name, is_optional, description.clone());
let create_object_type = |name: &str| {
Some(Type::Object(Object {