diff --git a/examples/demo/client/build.rs b/examples/demo/client/build.rs index 5c363c1ca..c47cc1e40 100644 --- a/examples/demo/client/build.rs +++ b/examples/demo/client/build.rs @@ -1,4 +1,5 @@ use demo::DemoProgram; +use sails_client_gen::ClientGenerator; use std::{env, path::PathBuf}; fn main() { @@ -8,10 +9,8 @@ fn main() { sails_idl_gen::generate_idl_to_file::(&idl_file_path).unwrap(); // Generate client code from IDL file - sails_client_gen::generate_client_from_idl( - &idl_file_path, - PathBuf::from(env::var("OUT_DIR").unwrap()).join("demo_client.rs"), - Some("with_mocks"), - ) - .unwrap(); + ClientGenerator::from_idl_path(&idl_file_path) + .with_mocks("with_mocks") + .generate_to(PathBuf::from(env::var("OUT_DIR").unwrap()).join("demo_client.rs")) + .unwrap(); } diff --git a/examples/no-svcs-prog/wasm/build.rs b/examples/no-svcs-prog/wasm/build.rs index e3b4fc892..07412d42c 100644 --- a/examples/no-svcs-prog/wasm/build.rs +++ b/examples/no-svcs-prog/wasm/build.rs @@ -1,4 +1,5 @@ use no_svcs_prog_app::Program; +use sails_client_gen::ClientGenerator; use std::{env, path::PathBuf}; fn main() { @@ -9,10 +10,7 @@ fn main() { sails_idl_gen::generate_idl_to_file::(&idl_file_path).unwrap(); - sails_client_gen::generate_client_from_idl( - &idl_file_path, - PathBuf::from(env::var("OUT_DIR").unwrap()).join("no_svcs_prog.rs"), - None, - ) - .unwrap(); + ClientGenerator::from_idl_path(&idl_file_path) + .generate_to(PathBuf::from(env::var("OUT_DIR").unwrap()).join("no_svcs_prog.rs")) + .unwrap(); } diff --git a/examples/rmrk/resource/app/build.rs b/examples/rmrk/resource/app/build.rs index 809804d84..e5423fc78 100644 --- a/examples/rmrk/resource/app/build.rs +++ b/examples/rmrk/resource/app/build.rs @@ -1,3 +1,4 @@ +use sails_client_gen::ClientGenerator; use std::{env, path::PathBuf}; fn main() { @@ -21,6 +22,8 @@ fn main() { let idl_file_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()) .join("..\\..\\catalog\\wasm\\rmrk-catalog.idl"); - sails_client_gen::generate_client_from_idl(idl_file_path, client_rs_file_path, Some("mockall")) + ClientGenerator::from_idl_path(&idl_file_path) + .with_mocks("mockall") + .generate_to(client_rs_file_path) .unwrap(); } diff --git a/examples/rmrk/resource/wasm/build.rs b/examples/rmrk/resource/wasm/build.rs index 84d7df977..6d1721576 100644 --- a/examples/rmrk/resource/wasm/build.rs +++ b/examples/rmrk/resource/wasm/build.rs @@ -1,4 +1,5 @@ use rmrk_resource_app::Program; +use sails_client_gen::ClientGenerator; use std::{env, path::PathBuf}; fn main() { @@ -12,5 +13,7 @@ fn main() { let out_dir_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let client_rs_file_path = out_dir_path.join("rmrk_resource.rs"); - sails_client_gen::generate_client_from_idl(idl_file_path, client_rs_file_path, None).unwrap(); + ClientGenerator::from_idl_path(&idl_file_path) + .generate_to(client_rs_file_path) + .unwrap(); } diff --git a/rs/client-gen/src/ctor_generators.rs b/rs/client-gen/src/ctor_generators.rs index 9d70792f5..7c6c12263 100644 --- a/rs/client-gen/src/ctor_generators.rs +++ b/rs/client-gen/src/ctor_generators.rs @@ -1,22 +1,23 @@ +use crate::{ + helpers::*, io_generators::generate_io_struct, type_generators::generate_type_decl_code, +}; use convert_case::{Case, Casing}; use genco::prelude::*; use rust::Tokens; use sails_idl_parser::{ast::visitor, ast::visitor::Visitor, ast::*}; -use crate::{ - helpers::*, io_generators::generate_io_struct, type_generators::generate_type_decl_code, -}; - -pub(crate) struct CtorFactoryGenerator { - service_name: String, +pub(crate) struct CtorFactoryGenerator<'a> { + service_name: &'a str, + sails_path: &'a str, tokens: Tokens, io_tokens: Tokens, } -impl CtorFactoryGenerator { - pub(crate) fn new(service_name: String) -> Self { +impl<'a> CtorFactoryGenerator<'a> { + pub(crate) fn new(service_name: &'a str, sails_path: &'a str) -> Self { Self { service_name, + sails_path, tokens: Tokens::new(), io_tokens: Tokens::new(), } @@ -30,7 +31,7 @@ impl CtorFactoryGenerator { use super::*; pub mod io { use super::*; - use sails_rs::calls::ActionIo; + use $(self.sails_path)::calls::ActionIo; $(self.io_tokens) } } @@ -38,15 +39,15 @@ impl CtorFactoryGenerator { } } -impl<'ast> Visitor<'ast> for CtorFactoryGenerator { +impl<'a, 'ast> Visitor<'ast> for CtorFactoryGenerator<'a> { fn visit_ctor(&mut self, ctor: &'ast Ctor) { quote_in! {self.tokens => - pub struct $(&self.service_name)Factory { + pub struct $(self.service_name)Factory { #[allow(dead_code)] remoting: R, } - impl $(&self.service_name)Factory { + impl $(self.service_name)Factory { #[allow(unused)] pub fn new(remoting: R) -> Self { Self { @@ -55,7 +56,7 @@ impl<'ast> Visitor<'ast> for CtorFactoryGenerator { } } - impl traits::$(&self.service_name)Factory for $(&self.service_name)Factory $("{") + impl traits::$(self.service_name)Factory for $(self.service_name)Factory $("{") type Args = R::Args; }; diff --git a/rs/client-gen/src/events_generator.rs b/rs/client-gen/src/events_generator.rs index 772241b2e..c776d60d1 100644 --- a/rs/client-gen/src/events_generator.rs +++ b/rs/client-gen/src/events_generator.rs @@ -1,19 +1,20 @@ +use crate::helpers::{method_bytes, path_bytes}; use genco::prelude::*; use sails_idl_parser::{ast::visitor, ast::visitor::Visitor, ast::*}; -use crate::helpers::{method_bytes, path_bytes}; - -pub(crate) struct EventsModuleGenerator { - service_name: String, - path: String, +pub(crate) struct EventsModuleGenerator<'a> { + service_name: &'a str, + path: &'a str, + sails_path: &'a str, tokens: rust::Tokens, } -impl EventsModuleGenerator { - pub(crate) fn new(service_name: String, path: String) -> Self { +impl<'a> EventsModuleGenerator<'a> { + pub(crate) fn new(service_name: &'a str, path: &'a str, sails_path: &'a str) -> Self { Self { service_name, path, + sails_path, tokens: rust::Tokens::new(), } } @@ -23,10 +24,10 @@ impl EventsModuleGenerator { } } -impl<'ast> Visitor<'ast> for EventsModuleGenerator { +impl<'a, 'ast> Visitor<'ast> for EventsModuleGenerator<'a> { fn visit_service(&mut self, service: &'ast Service) { let events_name = format!("{}Events", self.service_name); - let (service_path_bytes, _) = path_bytes(&self.path); + let (service_path_bytes, _) = path_bytes(self.path); let event_names_bytes = service .events() .iter() @@ -39,9 +40,9 @@ impl<'ast> Visitor<'ast> for EventsModuleGenerator { #[cfg(not(target_arch = "wasm32"))] pub mod events $("{") use super::*; - use sails_rs::events::*; + use $(self.sails_path)::events::*; #[derive(PartialEq, Debug, Encode, Decode)] - #[codec(crate = sails_rs::scale_codec)] + #[codec(crate = $(self.sails_path)::scale_codec)] pub enum $(&events_name) $("{") }; diff --git a/rs/client-gen/src/io_generators.rs b/rs/client-gen/src/io_generators.rs index 132367a9d..5e48873d8 100644 --- a/rs/client-gen/src/io_generators.rs +++ b/rs/client-gen/src/io_generators.rs @@ -1,18 +1,19 @@ -use genco::prelude::*; -use sails_idl_parser::{ast::visitor, ast::visitor::Visitor, ast::*}; - use crate::helpers::*; use crate::type_generators::generate_type_decl_with_path; +use genco::prelude::*; +use sails_idl_parser::{ast::visitor, ast::visitor::Visitor, ast::*}; -pub(crate) struct IoModuleGenerator { - path: String, +pub(crate) struct IoModuleGenerator<'a> { + path: &'a str, + sails_path: &'a str, tokens: rust::Tokens, } -impl IoModuleGenerator { - pub(crate) fn new(path: String) -> Self { +impl<'a> IoModuleGenerator<'a> { + pub(crate) fn new(path: &'a str, sails_path: &'a str) -> Self { Self { path, + sails_path, tokens: rust::Tokens::new(), } } @@ -21,21 +22,21 @@ impl IoModuleGenerator { quote!( pub mod io { use super::*; - use sails_rs::calls::ActionIo; + use $(self.sails_path)::calls::ActionIo; $(self.tokens) } ) } } -impl<'ast> Visitor<'ast> for IoModuleGenerator { +impl<'a, 'ast> Visitor<'ast> for IoModuleGenerator<'a> { fn visit_service(&mut self, service: &'ast Service) { visitor::accept_service(service, self); } fn visit_service_func(&mut self, func: &'ast ServiceFunc) { let fn_name = func.name(); - let (service_path_bytes, _) = path_bytes(&self.path); + let (service_path_bytes, _) = path_bytes(self.path); let (route_bytes, _) = method_bytes(fn_name); let struct_tokens = generate_io_struct( diff --git a/rs/client-gen/src/lib.rs b/rs/client-gen/src/lib.rs index 4a8e51ddf..fbbacf946 100644 --- a/rs/client-gen/src/lib.rs +++ b/rs/client-gen/src/lib.rs @@ -1,3 +1,9 @@ +use anyhow::{Context, Result}; +use convert_case::{Case, Casing}; +use root_generator::RootGenerator; +use sails_idl_parser::ast::visitor; +use std::{ffi::OsStr, fs, io::Write, path::Path}; + mod ctor_generators; mod events_generator; mod helpers; @@ -7,58 +13,106 @@ mod root_generator; mod service_generators; mod type_generators; -use root_generator::RootGenerator; +const SAILS: &str = "sails_rs"; -use anyhow::{Context, Result}; -use convert_case::{Case, Casing}; -use sails_idl_parser::ast::{visitor, Program}; -use std::{ffi::OsStr, fs, io::Write, path::Path}; +pub struct IdlPath<'a>(&'a Path); +pub struct IdlString<'a>(&'a str); +pub struct ClientGenerator<'a, S> { + sails_path: Option<&'a str>, + mocks_feature_name: Option<&'a str>, + idl: S, +} + +impl<'a, S> ClientGenerator<'a, S> { + pub fn with_mocks(self, mocks_feature_name: &'a str) -> Self { + Self { + mocks_feature_name: Some(mocks_feature_name), + ..self + } + } + + pub fn with_sails_crate(self, sails_path: &'a str) -> Self { + Self { + sails_path: Some(sails_path), + ..self + } + } +} -pub fn generate_client_from_idl( - idl_path: impl AsRef, - out_path: impl AsRef, - mocks_feature_name: Option<&str>, -) -> Result<()> { - let idl_path = idl_path.as_ref(); - let out_path = out_path.as_ref(); - - let idl = fs::read_to_string(idl_path) - .with_context(|| format!("Failed to open {} for reading", idl_path.display()))?; - - let program = match sails_idl_parser::ast::parse_idl(&idl) { - Ok(program) => program, - Err(e) => { - eprintln!("Failed to parse IDL: {}", e); - std::process::exit(1); +impl<'a> ClientGenerator<'a, IdlPath<'a>> { + pub fn from_idl_path(idl_path: &'a Path) -> Self { + Self { + sails_path: None, + mocks_feature_name: None, + idl: IdlPath(idl_path), } - }; + } - let file_name = idl_path.file_stem().unwrap_or(OsStr::new("service")); - let service_name = file_name.to_string_lossy().to_case(Case::Pascal); + pub fn generate_to(self, out_path: impl AsRef) -> Result<()> { + let idl_path = self.idl.0; - let buf = generate(program, &service_name, mocks_feature_name) - .context("failed to generate client")?; + let idl = fs::read_to_string(idl_path) + .with_context(|| format!("Failed to open {} for reading", idl_path.display()))?; - fs::write(out_path, buf) - .with_context(|| format!("Failed to write generated client to {}", out_path.display()))?; + let file_name = idl_path.file_stem().unwrap_or(OsStr::new("service")); + let service_name = file_name.to_string_lossy().to_case(Case::Pascal); - Ok(()) + self.with_idl(&idl) + .generate_to(&service_name, out_path) + .context("failed to generate client")?; + Ok(()) + } + + fn with_idl(self, idl: &'a str) -> ClientGenerator<'a, IdlString<'a>> { + ClientGenerator { + sails_path: self.sails_path, + mocks_feature_name: self.mocks_feature_name, + idl: IdlString(idl), + } + } } -pub fn generate( - program: Program, - anonymous_service_name: &str, - mocks_feature_name: Option<&str>, -) -> Result { - let mut generator = RootGenerator::new(anonymous_service_name, mocks_feature_name); - visitor::accept_program(&program, &mut generator); +impl<'a> ClientGenerator<'a, IdlString<'a>> { + pub fn from_idl(idl: &'a str) -> Self { + Self { + sails_path: None, + mocks_feature_name: None, + idl: IdlString(idl), + } + } + + pub fn generate(&self, anonymous_service_name: &str) -> Result { + let idl = self.idl.0; + let sails_path = self.sails_path.unwrap_or(SAILS); + let mut generator = + RootGenerator::new(anonymous_service_name, self.mocks_feature_name, sails_path); + let program = sails_idl_parser::ast::parse_idl(idl).context("Failed to parse IDL")?; + visitor::accept_program(&program, &mut generator); - let code = generator.finalize(); + let code = generator.finalize(); - // Check for parsing errors - let code = pretty_with_rustfmt(&code); + // Check for parsing errors + let code = pretty_with_rustfmt(&code); - Ok(code) + Ok(code) + } + + pub fn generate_to( + self, + anonymous_service_name: &str, + out_path: impl AsRef, + ) -> Result<()> { + let out_path = out_path.as_ref(); + let code = self + .generate(anonymous_service_name) + .context("failed to generate client")?; + + fs::write(out_path, code).with_context(|| { + format!("Failed to write generated client to {}", out_path.display()) + })?; + + Ok(()) + } } // not using prettyplease since it's bad at reporting syntax errors and also removes comments diff --git a/rs/client-gen/src/mock_generator.rs b/rs/client-gen/src/mock_generator.rs index f5450ee80..bacdcdad0 100644 --- a/rs/client-gen/src/mock_generator.rs +++ b/rs/client-gen/src/mock_generator.rs @@ -1,17 +1,16 @@ +use crate::type_generators::generate_type_decl_code; use convert_case::{Case, Casing}; use genco::prelude::*; use rust::Tokens; use sails_idl_parser::{ast::visitor, ast::visitor::Visitor, ast::*}; -use crate::type_generators::generate_type_decl_code; - -pub(crate) struct MockGenerator { - service_name: String, +pub(crate) struct MockGenerator<'a> { + service_name: &'a str, tokens: rust::Tokens, } -impl MockGenerator { - pub(crate) fn new(service_name: String) -> Self { +impl<'a> MockGenerator<'a> { + pub(crate) fn new(service_name: &'a str) -> Self { Self { service_name, tokens: rust::Tokens::new(), @@ -21,11 +20,11 @@ impl MockGenerator { pub(crate) fn finalize(self) -> rust::Tokens { quote! { mock! { - pub $(&self.service_name) {} + pub $(self.service_name) {} #[allow(refining_impl_trait)] #[allow(clippy::type_complexity)] - impl traits::$(&self.service_name) for $(&self.service_name) { + impl traits::$(self.service_name) for $(self.service_name) { type Args = A; $(self.tokens) } @@ -34,7 +33,7 @@ impl MockGenerator { } } -impl<'ast> Visitor<'ast> for MockGenerator { +impl<'a, 'ast> Visitor<'ast> for MockGenerator<'a> { fn visit_service(&mut self, service: &'ast Service) { visitor::accept_service(service, self); } diff --git a/rs/client-gen/src/root_generator.rs b/rs/client-gen/src/root_generator.rs index a43cfa0ef..735dfc124 100644 --- a/rs/client-gen/src/root_generator.rs +++ b/rs/client-gen/src/root_generator.rs @@ -13,18 +13,20 @@ pub(crate) struct RootGenerator<'a> { mocks_tokens: Tokens, anonymous_service_name: &'a str, mocks_feature_name: Option<&'a str>, + sails_path: &'a str, } impl<'a> RootGenerator<'a> { pub(crate) fn new( anonymous_service_name: &'a str, mocks_feature_name: Option<&'a str>, + sails_path: &'a str, ) -> Self { let tokens = quote! { #[allow(unused_imports)] - use sails_rs::{prelude::*, String, calls::{Activation, Call, Query, Remoting, RemotingAction}}; + use $sails_path::{prelude::*, String, calls::{Activation, Call, Query, Remoting, RemotingAction}}; #[allow(unused_imports)] - use sails_rs::collections::BTreeMap; + use $sails_path::collections::BTreeMap; }; Self { @@ -33,6 +35,7 @@ impl<'a> RootGenerator<'a> { traits_tokens: Tokens::new(), mocks_tokens: Tokens::new(), mocks_feature_name, + sails_path, } } @@ -47,7 +50,7 @@ impl<'a> RootGenerator<'a> { #[cfg(not(target_arch = "wasm32"))] pub mod mockall { use super::*; - use sails_rs::mockall::*; + use $(self.sails_path)::mockall::*; $(self.mocks_tokens) } } @@ -81,7 +84,7 @@ impl<'a, 'ast> Visitor<'ast> for RootGenerator<'a> { self.traits_tokens.extend(ctor_gen.finalize()); - let mut ctor_gen = CtorFactoryGenerator::new(self.anonymous_service_name.to_owned()); + let mut ctor_gen = CtorFactoryGenerator::new(self.anonymous_service_name, self.sails_path); ctor_gen.visit_ctor(ctor); self.tokens.extend(ctor_gen.finalize()); } @@ -106,13 +109,13 @@ impl<'a, 'ast> Visitor<'ast> for RootGenerator<'a> { let mut service_tokens = Tokens::new(); - let mut io_mod_gen = IoModuleGenerator::new(path.to_owned()); + let mut io_mod_gen = IoModuleGenerator::new(path, self.sails_path); io_mod_gen.visit_service(service); service_tokens.extend(io_mod_gen.finalize()); if !service.events().is_empty() { let mut events_mod_gen = - EventsModuleGenerator::new(service_name.to_owned(), path.to_owned()); + EventsModuleGenerator::new(service_name, path, self.sails_path); events_mod_gen.visit_service(service); service_tokens.extend(events_mod_gen.finalize()); } @@ -124,13 +127,13 @@ impl<'a, 'ast> Visitor<'ast> for RootGenerator<'a> { } } - let mut mock_gen: MockGenerator = MockGenerator::new(service_name.to_owned()); + let mut mock_gen: MockGenerator = MockGenerator::new(service_name); mock_gen.visit_service(service); self.mocks_tokens.extend(mock_gen.finalize()); } fn visit_type(&mut self, t: &'ast Type) { - let mut type_gen = TopLevelTypeGenerator::new(t.name()); + let mut type_gen = TopLevelTypeGenerator::new(t.name(), self.sails_path); type_gen.visit_type(t); self.tokens.extend(type_gen.finalize()); } diff --git a/rs/client-gen/src/type_generators.rs b/rs/client-gen/src/type_generators.rs index a92dcbb35..6cf520f6d 100644 --- a/rs/client-gen/src/type_generators.rs +++ b/rs/client-gen/src/type_generators.rs @@ -19,13 +19,15 @@ pub(crate) fn generate_type_decl_with_path(type_decl: &TypeDecl, path: String) - pub(crate) struct TopLevelTypeGenerator<'a> { type_name: &'a str, + sails_path: &'a str, tokens: Tokens, } impl<'a> TopLevelTypeGenerator<'a> { - pub(crate) fn new(type_name: &'a str) -> Self { + pub(crate) fn new(type_name: &'a str, sails_path: &'a str) -> Self { Self { type_name, + sails_path, tokens: Tokens::new(), } } @@ -48,8 +50,8 @@ impl<'a, 'ast> Visitor<'ast> for TopLevelTypeGenerator<'a> { quote_in!(self.tokens => #[derive(PartialEq, Debug, Encode, Decode, TypeInfo)] - #[codec(crate = sails_rs::scale_codec)] - #[scale_info(crate = sails_rs::scale_info)] + #[codec(crate = $(self.sails_path)::scale_codec)] + #[scale_info(crate = $(self.sails_path)::scale_info)] pub struct $(self.type_name) $(struct_def_generator.code) $(semi) ); } @@ -60,8 +62,8 @@ impl<'a, 'ast> Visitor<'ast> for TopLevelTypeGenerator<'a> { quote_in!(self.tokens => #[derive(PartialEq, Debug, Encode, Decode, TypeInfo)] - #[codec(crate = sails_rs::scale_codec)] - #[scale_info(crate = sails_rs::scale_info)] + #[codec(crate = $(self.sails_path)::scale_codec)] + #[scale_info(crate = $(self.sails_path)::scale_info)] pub enum $(self.type_name) $(enum_def_generator.code) ); } diff --git a/rs/client-gen/tests/generator.rs b/rs/client-gen/tests/generator.rs index 4d143eb5c..cdeaf5ea0 100644 --- a/rs/client-gen/tests/generator.rs +++ b/rs/client-gen/tests/generator.rs @@ -1,3 +1,5 @@ +use sails_client_gen::ClientGenerator; + #[test] fn full() { const IDL: &str = r#" @@ -127,8 +129,52 @@ fn test_events_works() { insta::assert_snapshot!(gen(idl, "ServiceWithEvents")); } -fn gen(program: &str, service_name: &str) -> String { - let program = sails_idl_parser::ast::parse_idl(program).expect("parse IDL"); +#[test] +fn full_with_sails_path() { + const IDL: &str = r#" + type ThisThatSvcAppTupleStruct = struct { + bool, + }; + + type ThisThatSvcAppDoThatParam = struct { + p1: u32, + p2: str, + p3: ThisThatSvcAppManyVariants, + }; - sails_client_gen::generate(program, service_name, Some("with_mocks")).expect("generate client") + type ThisThatSvcAppManyVariants = enum { + One, + Two: u32, + Three: opt u32, + Four: struct { a: u32, b: opt u16 }, + Five: struct { str, u32 }, + Six: struct { u32 }, + }; + + type T = enum { One }; + + constructor { + New : (a: u32); + }; + + service { + DoThis : (p1: u32, p2: str, p3: struct { opt str, u8 }, p4: ThisThatSvcAppTupleStruct) -> struct { str, u32 }; + DoThat : (param: ThisThatSvcAppDoThatParam) -> result (struct { str, u32 }, struct { str }); + query This : (v1: vec u16) -> u32; + query That : (v1: null) -> result (str, str); + }; + "#; + + let code = ClientGenerator::from_idl(IDL) + .with_sails_crate("my_crate::sails") + .generate("Service") + .expect("generate client"); + insta::assert_snapshot!(code); +} + +fn gen(program: &str, service_name: &str) -> String { + ClientGenerator::from_idl(program) + .with_mocks("with_mocks") + .generate(service_name) + .expect("generate client") } diff --git a/rs/client-gen/tests/snapshots/generator__full_with_sails_path.snap b/rs/client-gen/tests/snapshots/generator__full_with_sails_path.snap new file mode 100644 index 000000000..807654bdf --- /dev/null +++ b/rs/client-gen/tests/snapshots/generator__full_with_sails_path.snap @@ -0,0 +1,201 @@ +--- +source: rs/client-gen/tests/generator.rs +expression: "gen_with_path(IDL, \"Service\", None, Some(\"my_crate::sails\"))" +--- +// Code generated by sails-client-gen. DO NOT EDIT. +#[allow(unused_imports)] +use my_crate::sails::collections::BTreeMap; +#[allow(unused_imports)] +use my_crate::sails::{ + calls::{Activation, Call, Query, Remoting, RemotingAction}, + prelude::*, + String, +}; +pub struct ServiceFactory { + #[allow(dead_code)] + remoting: R, +} +impl ServiceFactory { + #[allow(unused)] + pub fn new(remoting: R) -> Self { + Self { remoting } + } +} +impl traits::ServiceFactory for ServiceFactory { + type Args = R::Args; + fn new(&self, a: u32) -> impl Activation { + RemotingAction::<_, service_factory::io::New>::new(self.remoting.clone(), a) + } +} +pub mod service_factory { + use super::*; + pub mod io { + use super::*; + use my_crate::sails::calls::ActionIo; + pub struct New(()); + impl New { + #[allow(dead_code)] + pub fn encode_call(a: u32) -> Vec { + ::encode_call(&a) + } + } + impl ActionIo for New { + const ROUTE: &'static [u8] = &[12, 78, 101, 119]; + type Params = u32; + type Reply = (); + } + } +} +pub struct Service { + remoting: R, +} +impl Service { + pub fn new(remoting: R) -> Self { + Self { remoting } + } +} +impl traits::Service for Service { + type Args = R::Args; + fn do_this( + &mut self, + p1: u32, + p2: String, + p3: (Option, u8), + p4: ThisThatSvcAppTupleStruct, + ) -> impl Call { + RemotingAction::<_, service::io::DoThis>::new(self.remoting.clone(), (p1, p2, p3, p4)) + } + fn do_that( + &mut self, + param: ThisThatSvcAppDoThatParam, + ) -> impl Call, Args = R::Args> { + RemotingAction::<_, service::io::DoThat>::new(self.remoting.clone(), param) + } + fn this(&self, v1: Vec) -> impl Query { + RemotingAction::<_, service::io::This>::new(self.remoting.clone(), v1) + } + fn that(&self, v1: ()) -> impl Query, Args = R::Args> { + RemotingAction::<_, service::io::That>::new(self.remoting.clone(), v1) + } +} +pub mod service { + use super::*; + pub mod io { + use super::*; + use my_crate::sails::calls::ActionIo; + pub struct DoThis(()); + impl DoThis { + #[allow(dead_code)] + pub fn encode_call( + p1: u32, + p2: String, + p3: (Option, u8), + p4: super::ThisThatSvcAppTupleStruct, + ) -> Vec { + ::encode_call(&(p1, p2, p3, p4)) + } + } + impl ActionIo for DoThis { + const ROUTE: &'static [u8] = &[24, 68, 111, 84, 104, 105, 115]; + type Params = ( + u32, + String, + (Option, u8), + super::ThisThatSvcAppTupleStruct, + ); + type Reply = (String, u32); + } + pub struct DoThat(()); + impl DoThat { + #[allow(dead_code)] + pub fn encode_call(param: super::ThisThatSvcAppDoThatParam) -> Vec { + ::encode_call(¶m) + } + } + impl ActionIo for DoThat { + const ROUTE: &'static [u8] = &[24, 68, 111, 84, 104, 97, 116]; + type Params = super::ThisThatSvcAppDoThatParam; + type Reply = Result<(String, u32), (String,)>; + } + pub struct This(()); + impl This { + #[allow(dead_code)] + pub fn encode_call(v1: Vec) -> Vec { + ::encode_call(&v1) + } + } + impl ActionIo for This { + const ROUTE: &'static [u8] = &[16, 84, 104, 105, 115]; + type Params = Vec; + type Reply = u32; + } + pub struct That(()); + impl That { + #[allow(dead_code)] + pub fn encode_call(v1: ()) -> Vec { + ::encode_call(&v1) + } + } + impl ActionIo for That { + const ROUTE: &'static [u8] = &[16, 84, 104, 97, 116]; + type Params = (); + type Reply = Result; + } + } +} +#[derive(PartialEq, Debug, Encode, Decode, TypeInfo)] +#[codec(crate = my_crate::sails::scale_codec)] +#[scale_info(crate = my_crate::sails::scale_info)] +pub struct ThisThatSvcAppTupleStruct(pub bool); +#[derive(PartialEq, Debug, Encode, Decode, TypeInfo)] +#[codec(crate = my_crate::sails::scale_codec)] +#[scale_info(crate = my_crate::sails::scale_info)] +pub struct ThisThatSvcAppDoThatParam { + pub p1: u32, + pub p2: String, + pub p3: ThisThatSvcAppManyVariants, +} +#[derive(PartialEq, Debug, Encode, Decode, TypeInfo)] +#[codec(crate = my_crate::sails::scale_codec)] +#[scale_info(crate = my_crate::sails::scale_info)] +pub enum ThisThatSvcAppManyVariants { + One, + Two(u32), + Three(Option), + Four { a: u32, b: Option }, + Five((String, u32)), + Six((u32,)), +} +#[derive(PartialEq, Debug, Encode, Decode, TypeInfo)] +#[codec(crate = my_crate::sails::scale_codec)] +#[scale_info(crate = my_crate::sails::scale_info)] +pub enum T { + One, +} +pub mod traits { + use super::*; + #[allow(dead_code)] + pub trait ServiceFactory { + type Args; + #[allow(clippy::new_ret_no_self)] + #[allow(clippy::wrong_self_convention)] + fn new(&self, a: u32) -> impl Activation; + } + #[allow(clippy::type_complexity)] + pub trait Service { + type Args; + fn do_this( + &mut self, + p1: u32, + p2: String, + p3: (Option, u8), + p4: ThisThatSvcAppTupleStruct, + ) -> impl Call; + fn do_that( + &mut self, + param: ThisThatSvcAppDoThatParam, + ) -> impl Call, Args = Self::Args>; + fn this(&self, v1: Vec) -> impl Query; + fn that(&self, v1: ()) -> impl Query, Args = Self::Args>; + } +}