diff --git a/external-dependencies/Cargo.toml b/external-dependencies/Cargo.toml index 2e8ea3d..32c56fd 100644 --- a/external-dependencies/Cargo.toml +++ b/external-dependencies/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "external-dependencies" -version = "0.6.3" +version = "0.6.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/my-grpc-client-macros/Cargo.toml b/my-grpc-client-macros/Cargo.toml index 2016aa3..014ef3d 100644 --- a/my-grpc-client-macros/Cargo.toml +++ b/my-grpc-client-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "my-grpc-client-macros" -version = "0.6.3" +version = "0.6.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,7 +14,7 @@ with-ssh = [] proc-macro = true [dependencies] -types-reader = { tag = "0.3.0", git = "https://github.com/MyJetTools/types-reader.git" } +types-reader = { tag = "0.5.1", git = "https://github.com/MyJetTools/types-reader.git" } syn = { version = "*", features = ["extra-traits"] } quote = "*" diff --git a/my-grpc-client-macros/src/grpc_client/fn_override.rs b/my-grpc-client-macros/src/grpc_client/fn_override.rs index 915378d..6e30ff0 100644 --- a/my-grpc-client-macros/src/grpc_client/fn_override.rs +++ b/my-grpc-client-macros/src/grpc_client/fn_override.rs @@ -1,46 +1,39 @@ use std::collections::HashMap; -use proc_macro2::TokenStream; -use types_reader::ParamsList; +use types_reader::TokensObject; pub struct FnOverride<'s> { pub retries: usize, - pub token_stream: &'s TokenStream, + pub token_stream: &'s TokensObject, } impl<'s> FnOverride<'s> { - pub fn new(attributes: &'s ParamsList) -> Result, syn::Error> { - let overrides = attributes.try_get_named_param("overrides"); + pub fn new(params: &'s TokensObject) -> Result, syn::Error> { + let overrides = params.try_get_named_param("overrides"); if overrides.is_none() { return Ok(HashMap::new()); } - let tokens_list = overrides.unwrap(); - - let overrides = tokens_list.unwrap_as_object_list()?; + let overrides = overrides.unwrap().unwrap_as_vec()?; let mut result = HashMap::new(); for item in overrides.iter() { - let name = item - .get_named_param("fn_name")? - .unwrap_as_string_value()? - .to_string(); + let name: String = item.get_named_param("fn_name")?.try_into()?; + + let retries: usize = item.get_named_param("retries")?.try_into()?; result.insert( name, FnOverride { - retries: item - .get_named_param("retries")? - .unwrap_as_number_value()? - .as_usize(), - token_stream: item.get_token_stream(), + retries, + token_stream: item, }, ); } if result.len() == 0 { - return Err(tokens_list.throw_error("Overrides list can not be empty. Just remove field if you do not want to override any function")); + return Err(params.throw_error_at_param_token("Overrides list can not be empty. Just remove field if you do not want to override any function")); } Ok(result) diff --git a/my-grpc-client-macros/src/grpc_client/generate.rs b/my-grpc-client-macros/src/grpc_client/generate.rs index 1fc3acb..b5bbdfa 100644 --- a/my-grpc-client-macros/src/grpc_client/generate.rs +++ b/my-grpc-client-macros/src/grpc_client/generate.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use proc_macro::TokenStream; -use types_reader::ParamsList; +use types_reader::TokensObject; use crate::grpc_client::{fn_override::FnOverride, proto_file_reader::into_snake_case}; @@ -23,39 +23,33 @@ pub fn generate( - let attr_input: proc_macro2::TokenStream = attr.into(); + let attr: proc_macro2::TokenStream = attr.into(); - let attributes = ParamsList::new(attr_input, ||None)?; + let params_list = TokensObject::new(attr.into())?; - let timeout_sec = attributes.get_named_param("request_timeout_sec")?; - let timeout_sec = timeout_sec.unwrap_as_number_value()?.as_literal(); - let ping_timeout_sec = attributes.get_named_param("ping_timeout_sec")?; - let ping_timeout_sec = ping_timeout_sec.unwrap_as_number_value()?.as_literal(); + let proto_file:String = params_list.get_named_param("proto_file")?.try_into()?; - let ping_interval_sec = attributes.get_named_param("ping_interval_sec")?; - let ping_interval_sec = ping_interval_sec.unwrap_as_number_value()?.as_literal(); - - let proto_file = attributes.get_named_param("proto_file")?; - let proto_file = proto_file.unwrap_as_string_value()?.as_str(); - let proto_file = ProtoServiceDescription::read_proto_file(proto_file); + let proto_file = ProtoServiceDescription::read_proto_file(&proto_file); let grpc_service_name = &proto_file.service_name; let grpc_service_name_token = proto_file.get_service_name_as_token(); let interfaces = super::generate_interfaces_implementations(struct_name, &proto_file); - let retries = attributes.get_named_param("retries")?; - let retries = retries.unwrap_as_number_value()?.as_usize(); - - let overrides = FnOverride::new(&attributes)?; + let overrides = FnOverride::new(¶ms_list)?; + let ping_timeout_sec:usize = params_list.get_named_param("ping_timeout_sec")?.try_into()?; + let ping_interval_sec:usize = params_list.get_named_param("ping_interval_sec")?.try_into()?; + let timeout_sec:usize = params_list.get_named_param("request_timeout_sec")?.try_into()?; + let retries:usize = params_list.get_named_param("retries")?.try_into()?; + - let crate_ns = attributes.get_named_param("crate_ns")?.unwrap_as_string_value()?.as_str(); + let crate_ns:String = params_list.get_named_param("crate_ns")?.try_into()?; let mut use_name_spaces = Vec::new(); use_name_spaces.push(proc_macro2::TokenStream::from_str(format!("use {}::*", crate_ns).as_str()).unwrap()); @@ -63,19 +57,16 @@ pub fn generate( use_name_spaces.push(proc_macro2::TokenStream::from_str(ns_of_client.as_str()).unwrap()); - let settings_service_name = if let Some(service_name) = attributes.try_get_named_param("service_name"){ - service_name.unwrap_as_string_value()?.as_str().to_string() - + let settings_service_name = if let Some(service_name) = params_list.try_get_named_param("service_name"){ + service_name.unwrap_as_value()?.as_string()?.to_string() }else{ struct_name.to_string() }; for (override_fn_name, fn_override) in &overrides{ if !proto_file.has_method(override_fn_name){ - return Err(syn::Error::new_spanned( - fn_override.token_stream.clone(), - format!("Method {} is not found in proto file for service {}", override_fn_name, grpc_service_name), - )); + let message = format!("Method {} is not found in proto file for service {}", override_fn_name, grpc_service_name); + return Err(fn_override.token_stream.throw_error_at_value_token(message.as_str())); } } diff --git a/my-grpc-client-macros/src/grpc_client/mod.rs b/my-grpc-client-macros/src/grpc_client/mod.rs index efc78e4..06290aa 100644 --- a/my-grpc-client-macros/src/grpc_client/mod.rs +++ b/my-grpc-client-macros/src/grpc_client/mod.rs @@ -11,3 +11,5 @@ pub use generate_interfaces_implementations::*; pub use param_type::*; mod generate; pub use generate::*; +//mod attr_params; +//pub use attr_params::*; diff --git a/my-grpc-extensions/Cargo.toml b/my-grpc-extensions/Cargo.toml index 9e671fe..5258d48 100644 --- a/my-grpc-extensions/Cargo.toml +++ b/my-grpc-extensions/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "my-grpc-extensions" -version = "0.6.3" +version = "0.6.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -17,19 +17,19 @@ with-ssh = ["my-ssh", "my-grpc-client-macros?/with-ssh"] [dependencies] -my-telemetry = { tag = "1.2.0", git = "https://github.com/MyJetTools/my-telemetry.git", features = [ +my-telemetry = { tag = "1.2.1", git = "https://github.com/MyJetTools/my-telemetry.git", features = [ "my-telemetry-writer", ], optional = true } -my-logger = { tag = "1.1.0", git = "https://github.com/MyJetTools/my-logger.git" } -rust-extensions = { tag = "0.1.4", git = "https://github.com/MyJetTools/rust-extensions.git", features = [ +my-logger = { tag = "1.2.1", git = "https://github.com/MyJetTools/my-logger.git" } +rust-extensions = { tag = "0.1.5", git = "https://github.com/MyJetTools/rust-extensions.git", features = [ "with-tokio", ] } lazy_static = "*" -my-tls = { tag = "0.1.1", git = "https://github.com/MyJetTools/my-tls.git", optional = true } +my-tls = { tag = "0.1.5", git = "https://github.com/MyJetTools/my-tls.git", optional = true } tokio = { version = "*", features = ["full"] } tonic = { version = "*", features = ["tls", "tls-roots", "prost"] } hyper = { version = "*" } @@ -39,7 +39,7 @@ tokio-stream = "*" futures = "*" async-trait = "*" tower = { version = "*" } -my-ssh = { tag = "0.1.1", git = "https://github.com/MyJetTools/my-ssh.git", optional = true } +my-ssh = { tag = "0.1.2", git = "https://github.com/MyJetTools/my-ssh.git", optional = true } my-grpc-client-macros = { optional = true, path = "../my-grpc-client-macros" } my-grpc-server-macros = { optional = true, path = "../my-grpc-server-macros" } external-dependencies = { path = "../external-dependencies" } diff --git a/my-grpc-server-macros/Cargo.toml b/my-grpc-server-macros/Cargo.toml index d8cb4a7..55d09e2 100644 --- a/my-grpc-server-macros/Cargo.toml +++ b/my-grpc-server-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "my-grpc-server-macros" -version = "0.6.3" +version = "0.6.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -9,7 +9,7 @@ edition = "2021" proc-macro = true [dependencies] -types-reader = { tag = "0.3.0", git = "https://github.com/MyJetTools/types-reader.git" } +types-reader = { tag = "0.5.1", git = "https://github.com/MyJetTools/types-reader.git" } syn = { version = "*", features = ["extra-traits"] } quote = "*" diff --git a/my-grpc-server-macros/src/generate_server_stream/generate_server_stream.rs b/my-grpc-server-macros/src/generate_server_stream/generate_server_stream.rs index b4df7d9..ff885b8 100644 --- a/my-grpc-server-macros/src/generate_server_stream/generate_server_stream.rs +++ b/my-grpc-server-macros/src/generate_server_stream/generate_server_stream.rs @@ -1,15 +1,13 @@ use proc_macro::TokenStream; +use types_reader::TokensObject; pub fn generate_server_stream(tokens: TokenStream) -> Result { - let params_list = types_reader::ParamsList::new(tokens.into(), || None)?; + let tokens: proc_macro2::TokenStream = tokens.into(); + let params_list = TokensObject::new(tokens.into())?; - let stream_name = params_list.get_named_param("stream_name")?; + let stream_name: &str = params_list.get_named_param("stream_name")?.try_into()?; - let item_name = params_list.get_named_param("item_name")?; + let item_name: &str = params_list.get_named_param("item_name")?.try_into()?; - Ok(crate::generate_stream::generate_stream( - stream_name.unwrap_as_string_value()?.as_str(), - item_name.unwrap_as_string_value()?.as_str(), - ) - .into()) + Ok(crate::generate_stream::generate_stream(stream_name, item_name).into()) } diff --git a/my-grpc-server-macros/src/with_result_stream/generate.rs b/my-grpc-server-macros/src/with_result_stream/generate.rs index 572ec79..89948e9 100644 --- a/my-grpc-server-macros/src/with_result_stream/generate.rs +++ b/my-grpc-server-macros/src/with_result_stream/generate.rs @@ -1,19 +1,21 @@ +use types_reader::TokensObject; + pub fn generate( attr: proc_macro::TokenStream, input: proc_macro::TokenStream, ) -> Result { - let params_list = types_reader::ParamsList::new(attr.into(), || None)?; + let tokens: proc_macro2::TokenStream = attr.into(); + let params_list = TokensObject::new(tokens.into())?; - let item_name = params_list.get_from_single_or_named("item_name")?; + let item_name: &str = params_list + .get_value_from_single_or_named("item_name")? + .try_into()?; let content = input.to_string(); let stream_name = find_stream_name(content.as_str()); - let stream_implementation = crate::generate_stream::generate_stream( - stream_name, - item_name.unwrap_as_string_value()?.as_str(), - ); + let stream_implementation = crate::generate_stream::generate_stream(stream_name, item_name); let input: proc_macro2::TokenStream = input.into(); @@ -64,7 +66,6 @@ fn find_stream_name(content: &str) -> &str { stream_name.unwrap() } - #[cfg(test)] mod tests {