Skip to content

Commit

Permalink
Add FiegnClient trait + derive
Browse files Browse the repository at this point in the history
Add #[path] #[query] #[param] #[header] parameters inside FeignClients
  • Loading branch information
ajuvercr committed Dec 18, 2022
1 parent ff189af commit 6cf8a8d
Show file tree
Hide file tree
Showing 21 changed files with 618 additions and 397 deletions.
26 changes: 14 additions & 12 deletions codegen/src/enu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt;
use std::{fmt, str::FromStr};

/// Http request method.
pub enum Method {
Expand Down Expand Up @@ -29,7 +29,7 @@ impl Method {
}

/// Arg type.
#[derive(PartialEq)]
#[derive(PartialEq, Clone)]
pub enum ArgType {
HEADER,
PATH,
Expand All @@ -53,16 +53,18 @@ impl fmt::Display for ArgType {
}
}

impl ArgType {
pub fn from_str(arg_type: &str) -> Result<ArgType, String> {
match arg_type {
"header" | "HEADER" => Ok(ArgType::HEADER),
"path" | "PATH" => Ok(ArgType::PATH),
"query" | "QUERY" => Ok(ArgType::QUERY),
"form" | "FORM" => Ok(ArgType::FORM),
"body" | "BODY" => Ok(ArgType::BODY),
"param" | "PARAM" => Ok(ArgType::PARAM),
_ => Err("unknown arg type: ".to_string() + arg_type),
impl FromStr for ArgType {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"header" => Ok(ArgType::HEADER),
"path" | "url_path" => Ok(ArgType::PATH),
"query" => Ok(ArgType::QUERY),
"form" => Ok(ArgType::FORM),
"body" => Ok(ArgType::BODY),
"param" => Ok(ArgType::PARAM),
_ => Err("unknown arg type: ".to_string() + s),
}
}
}
Loading

0 comments on commit 6cf8a8d

Please sign in to comment.