File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ pub struct FaviconArgs {
1111 favicon : Option < String > ,
1212}
1313
14- pub struct Favicon {
15- favicon : Option < String > ,
14+ pub struct Favicon < ' a > {
15+ args : & ' a FaviconArgs ,
1616}
1717
1818async fn do_favicon_output ( favicon : & str , output : & str ) -> std:: io:: Result < ( ) > {
@@ -24,15 +24,15 @@ async fn do_favicon_output(favicon: &str, output: &str) -> std::io::Result<()> {
2424}
2525
2626#[ async_trait]
27- impl Analyzer for Favicon {
27+ impl Analyzer for Favicon < ' _ > {
2828 fn enabled ( & self , payload : & StatusPayload ) -> bool {
29- self . favicon . is_some ( ) && payload. favicon . is_some ( )
29+ self . args . favicon . is_some ( ) && payload. favicon . is_some ( )
3030 }
3131
3232 async fn analyze ( & self , payload : & StatusPayload ) {
3333 match do_favicon_output (
3434 & payload. favicon . as_ref ( ) . unwrap ( ) ,
35- & self . favicon . as_ref ( ) . unwrap ( ) ,
35+ & self . args . favicon . as_ref ( ) . unwrap ( ) ,
3636 )
3737 . await
3838 {
@@ -42,10 +42,8 @@ impl Analyzer for Favicon {
4242 }
4343}
4444
45- impl Favicon {
46- pub fn new ( args : & FaviconArgs ) -> Favicon {
47- Favicon {
48- favicon : args. favicon . clone ( ) ,
49- }
45+ impl Favicon < ' _ > {
46+ pub fn new ( args : & ' _ FaviconArgs ) -> Favicon < ' _ > {
47+ Favicon { args }
5048 }
5149}
Original file line number Diff line number Diff line change @@ -51,11 +51,11 @@ pub trait Analyzer {
5151 async fn analyze ( & self , payload : & StatusPayload ) ;
5252}
5353
54- pub struct AnalyzerTools {
55- analyzers : Vec < Box < dyn Analyzer > > ,
54+ pub struct AnalyzerTools < ' a > {
55+ analyzers : Vec < Box < dyn Analyzer + ' a > > ,
5656}
5757
58- impl AnalyzerTools {
58+ impl AnalyzerTools < ' _ > {
5959 pub async fn analyze ( & self , payload : & StatusPayload ) {
6060 for analyzer in self . analyzers . iter ( ) {
6161 if analyzer. enabled ( & payload) {
@@ -86,7 +86,7 @@ pub struct AnalyzerArgs {
8686 favicon_args : FaviconArgs ,
8787}
8888
89- pub fn init_analyzer_tools ( args : & AnalyzerArgs ) -> AnalyzerTools {
89+ pub fn init_analyzer_tools < ' a > ( args : & ' _ AnalyzerArgs ) -> AnalyzerTools < ' _ > {
9090 let mut analyzers: Vec < Box < dyn Analyzer > > = Vec :: new ( ) ;
9191
9292 if args. analyzers . contains ( & AvailableAnalyzers :: PING ) {
Original file line number Diff line number Diff line change @@ -15,14 +15,12 @@ pub struct PlayerArgs {
1515 hide_anonymous : bool ,
1616}
1717
18- pub struct Player {
19- no_player_list : bool ,
20- no_uuid : bool ,
21- hide_anonymous : bool ,
18+ pub struct Player < ' a > {
19+ args : & ' a PlayerArgs ,
2220}
2321
2422#[ async_trait]
25- impl Analyzer for Player {
23+ impl Analyzer for Player < ' _ > {
2624 fn enabled ( & self , payload : & StatusPayload ) -> bool {
2725 payload. max_players . is_some ( ) && payload. player_count . is_some ( )
2826 }
@@ -33,14 +31,15 @@ impl Analyzer for Player {
3331 payload. player_count. unwrap( ) ,
3432 payload. max_players. unwrap( )
3533 ) ;
36- if !self . no_player_list
34+ if !self . args . no_player_list
3735 && let Some ( players) = payload. players . as_ref ( )
3836 {
3937 for player in players {
40- if self . hide_anonymous && player. uuid == "00000000-0000-0000-0000-000000000000" {
38+ if self . args . hide_anonymous && player. uuid == "00000000-0000-0000-0000-000000000000"
39+ {
4140 continue ;
4241 }
43- if self . no_uuid {
42+ if self . args . no_uuid {
4443 log:: info!( " {}" , player. id) ;
4544 } else {
4645 log:: info!( " {:20} ({})" , player. id, player. uuid) ;
@@ -50,12 +49,8 @@ impl Analyzer for Player {
5049 }
5150}
5251
53- impl Player {
54- pub fn new ( args : & PlayerArgs ) -> Player {
55- Player {
56- no_player_list : args. no_player_list ,
57- no_uuid : args. no_uuid ,
58- hide_anonymous : args. hide_anonymous ,
59- }
52+ impl Player < ' _ > {
53+ pub fn new ( args : & ' _ PlayerArgs ) -> Player < ' _ > {
54+ Player { args }
6055 }
6156}
Original file line number Diff line number Diff line change @@ -149,18 +149,17 @@ pub struct JavaModeArgs {
149149 pub protocol : i32 ,
150150}
151151
152- pub struct JavaQuery {
153- pub no_srv : bool ,
154- pub protocol : i32 ,
152+ pub struct JavaQuery < ' a > {
153+ args : & ' a JavaModeArgs ,
155154}
156155
157156#[ async_trait]
158- impl QueryModeHandler for JavaQuery {
157+ impl QueryModeHandler for JavaQuery < ' _ > {
159158 async fn do_query ( & self , addr : & str ) -> std:: io:: Result < StatusPayload > {
160159 let mut je_res = resolve_addr ( addr, 25565 ) ;
161160 let je_address = je_res. get_or_insert_default ( ) ;
162161
163- if !self . no_srv {
162+ if !self . args . no_srv {
164163 let srv_res = resolve_server_srv ( addr) . await ;
165164 let srv = srv_res
166165 . iter ( )
@@ -169,15 +168,12 @@ impl QueryModeHandler for JavaQuery {
169168 je_address. splice ( 0 ..0 , srv) ;
170169 }
171170
172- check_java_server ( je_address, self . protocol ) . await
171+ check_java_server ( je_address, self . args . protocol ) . await
173172 }
174173}
175174
176- impl JavaQuery {
177- pub fn new ( args : & JavaModeArgs ) -> JavaQuery {
178- JavaQuery {
179- no_srv : args. no_srv ,
180- protocol : args. protocol ,
181- }
175+ impl JavaQuery < ' _ > {
176+ pub fn new ( args : & ' _ JavaModeArgs ) -> JavaQuery < ' _ > {
177+ JavaQuery { args }
182178 }
183179}
Original file line number Diff line number Diff line change @@ -134,17 +134,17 @@ async fn check_legacy_server(addr_vec: &Vec<SocketAddr>) -> std::io::Result<Stat
134134 Err ( std:: io:: Error :: new ( ErrorKind :: NotFound , "No server found" ) )
135135}
136136
137- pub struct LegacyQuery {
138- pub no_srv : bool ,
137+ pub struct LegacyQuery < ' a > {
138+ args : & ' a JavaModeArgs ,
139139}
140140
141141#[ async_trait]
142- impl QueryModeHandler for LegacyQuery {
142+ impl QueryModeHandler for LegacyQuery < ' _ > {
143143 async fn do_query ( & self , addr : & str ) -> std:: io:: Result < StatusPayload > {
144144 let mut res = resolve_addr ( addr, 25565 ) ;
145145 let addrs = res. get_or_insert_default ( ) ;
146146
147- if !self . no_srv {
147+ if !self . args . no_srv {
148148 let srv_res = resolve_server_srv ( addr) . await ;
149149 let srv = srv_res
150150 . iter ( )
@@ -157,10 +157,8 @@ impl QueryModeHandler for LegacyQuery {
157157 }
158158}
159159
160- impl LegacyQuery {
161- pub fn new ( args : & JavaModeArgs ) -> LegacyQuery {
162- LegacyQuery {
163- no_srv : args. no_srv ,
164- }
160+ impl LegacyQuery < ' _ > {
161+ pub fn new ( args : & ' _ JavaModeArgs ) -> LegacyQuery < ' _ > {
162+ LegacyQuery { args }
165163 }
166164}
Original file line number Diff line number Diff line change @@ -24,11 +24,11 @@ trait QueryModeHandler {
2424 async fn do_query ( & self , addr : & str ) -> std:: io:: Result < StatusPayload > ;
2525}
2626
27- pub struct QueryEngine {
28- modes : HashMap < QueryMode , Box < dyn QueryModeHandler > > ,
27+ pub struct QueryEngine < ' a > {
28+ modes : HashMap < QueryMode , Box < dyn QueryModeHandler + ' a > > ,
2929}
3030
31- impl QueryEngine {
31+ impl QueryEngine < ' _ > {
3232 pub async fn query ( & self , mode : QueryMode , addr : & str ) -> std:: io:: Result < StatusPayload > {
3333 if let Some ( handler) = self . modes . get ( & mode) {
3434 handler. do_query ( addr) . await
@@ -47,7 +47,7 @@ pub struct ModeArgs {
4747 java : JavaModeArgs ,
4848}
4949
50- pub fn init_query_engine ( args : & ModeArgs ) -> QueryEngine {
50+ pub fn init_query_engine ( args : & ' _ ModeArgs ) -> QueryEngine < ' _ > {
5151 let mut modes: HashMap < QueryMode , Box < dyn QueryModeHandler > > = HashMap :: new ( ) ;
5252 modes. insert ( JAVA , Box :: new ( JavaQuery :: new ( & args. java ) ) ) ;
5353 modes. insert ( LEGACY , Box :: new ( LegacyQuery :: new ( & args. java ) ) ) ;
You can’t perform that action at this time.
0 commit comments