File tree Expand file tree Collapse file tree
behavioral/chain_of_responsibility Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99## Template List
1010
1111Template name | Type | Status | Links |
12- :-----------------------|:----------:|- ------:|:----------------------------------------------------------------------|
12+ :-----------------------|:----------:|: ------:|:----------------------------------------------------------------------|
1313Abstract Factory | Creational | ✅ | [ Wiki] ( https://en.wikipedia.org/wiki/Abstract_factory_pattern ) |
1414Adapter | Structural | ✅ | [ Wiki] ( https://en.wikipedia.org/wiki/Adapter_pattern ) |
1515Bridge | Structural | ✅ | [ Wiki] ( https://en.wikipedia.org/wiki/Bridge_pattern ) |
Original file line number Diff line number Diff line change @@ -22,3 +22,9 @@ impl Garage {
2222 }
2323 }
2424}
25+
26+ impl Default for Garage {
27+ fn default ( ) -> Self {
28+ Self :: new ( )
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -31,9 +31,9 @@ impl Policeman for Detective {
3131 self . name
3232 ) ;
3333
34- match & self . next {
35- & Some ( ref next) => next. investigate ( crime) ,
36- & None => println ! ( "Detective {}: Unimpossible for our department" , self . name) ,
34+ match self . next {
35+ Some ( ref next) => next. investigate ( crime) ,
36+ None => println ! ( "Detective {}: Unimpossible for our department" , self . name) ,
3737 }
3838 } else {
3939 println ! ( "Detective {}: I can do this." , self . name) ;
@@ -69,9 +69,9 @@ impl Policeman for Patrolman {
6969 self . name
7070 ) ;
7171
72- match & self . next {
73- & Some ( ref next) => next. investigate ( crime) ,
74- & None => println ! ( "Patrolman {}: Unimpossible for our department." , self . name) ,
72+ match self . next {
73+ Some ( ref next) => next. investigate ( crime) ,
74+ None => println ! ( "Patrolman {}: Unimpossible for our department." , self . name) ,
7575 }
7676 } else {
7777 println ! ( "Patrolman {}: It's easy. I can do this." , self . name) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ impl CheapLaunch {
5050 }
5151}
5252
53+ impl Default for CheapLaunch {
54+ fn default ( ) -> Self {
55+ Self :: new ( )
56+ }
57+ }
58+
5359impl Launch < CheapCourse , CheapDrink > for CheapLaunch {
5460 fn get_main_course ( & self ) -> CheapCourse {
5561 self . main_course
@@ -74,6 +80,12 @@ impl BusinessLaunch {
7480 }
7581}
7682
83+ impl Default for BusinessLaunch {
84+ fn default ( ) -> Self {
85+ Self :: new ( )
86+ }
87+ }
88+
7789impl Launch < BusinessCourse , BusinessDrink > for BusinessLaunch {
7890 fn get_main_course ( & self ) -> BusinessCourse {
7991 self . main_course
Original file line number Diff line number Diff line change @@ -54,6 +54,12 @@ impl ConfigBuilder {
5454 }
5555}
5656
57+ impl Default for ConfigBuilder {
58+ fn default ( ) -> Self {
59+ Self :: new ( )
60+ }
61+ }
62+
5763impl fmt:: Display for Config {
5864 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5965 write ! (
Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ impl HtmlReportBuilder {
3636 }
3737}
3838
39+ impl Default for HtmlReportBuilder {
40+ fn default ( ) -> Self {
41+ Self :: new ( )
42+ }
43+ }
44+
3945impl ReportBuilder < HtmlReportBuilder > for HtmlReportBuilder {
4046 fn with_header < S : Into < String > + Display > ( mut self , header : S ) -> HtmlReportBuilder {
4147 self . content . push_str ( & format ! ( "<h1>{}</h1>\n " , header) ) ;
@@ -72,6 +78,12 @@ impl MarkdownReportBuilder {
7278 }
7379}
7480
81+ impl Default for MarkdownReportBuilder {
82+ fn default ( ) -> Self {
83+ Self :: new ( )
84+ }
85+ }
86+
7587impl ReportBuilder < MarkdownReportBuilder > for MarkdownReportBuilder {
7688 fn with_header < S : Into < String > + Display > ( mut self , header : S ) -> MarkdownReportBuilder {
7789 self . content . push_str ( & format ! ( "# {}\n \n " , header) ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,12 @@ impl HtmlReport {
1515 }
1616}
1717
18+ impl Default for HtmlReport {
19+ fn default ( ) -> Self {
20+ Self :: new ( )
21+ }
22+ }
23+
1824impl Report for HtmlReport {
1925 fn set_header < S : Into < String > > ( & mut self , header : S ) {
2026 self . header = header. into ( ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,12 @@ impl MarkdownReport {
1515 }
1616}
1717
18+ impl Default for MarkdownReport {
19+ fn default ( ) -> Self {
20+ Self :: new ( )
21+ }
22+ }
23+
1824impl Report for MarkdownReport {
1925 fn set_header < S : Into < String > > ( & mut self , header : S ) {
2026 self . header = header. into ( ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ impl ChiefAdapter {
1616 }
1717}
1818
19+ impl Default for ChiefAdapter {
20+ fn default ( ) -> Self {
21+ Self :: new ( )
22+ }
23+ }
24+
1925impl Chief for ChiefAdapter {
2026 fn get_cost ( & self ) -> u32 {
2127 self . confectioner . get_cost_for_dinner ( )
@@ -49,3 +55,9 @@ impl Confectioner {
4955 println ! ( "Thanks for ${}" , money) ;
5056 }
5157}
58+
59+ impl Default for Confectioner {
60+ fn default ( ) -> Self {
61+ Self :: new ( )
62+ }
63+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ pub trait ComponentUnit {
44 fn get_strength ( & self ) -> i32 ;
55 fn add_unit ( & mut self , unit : Box < dyn ComponentUnit > ) ;
66 fn get_units ( & self ) -> & Vec < Box < dyn ComponentUnit > > ;
7- fn get_unit ( & self , index : usize ) -> & Box < dyn ComponentUnit > ;
7+ fn get_unit ( & self , index : usize ) -> & dyn ComponentUnit ;
88 fn remove ( & mut self , index : usize ) ;
99}
1010
@@ -18,6 +18,12 @@ impl CompositeUnit {
1818 }
1919}
2020
21+ impl Default for CompositeUnit {
22+ fn default ( ) -> Self {
23+ Self :: new ( )
24+ }
25+ }
26+
2127impl ComponentUnit for CompositeUnit {
2228 fn get_strength ( & self ) -> i32 {
2329 let mut res = 0 ;
@@ -37,8 +43,8 @@ impl ComponentUnit for CompositeUnit {
3743 & self . units
3844 }
3945
40- fn get_unit ( & self , index : usize ) -> & Box < dyn ComponentUnit > {
41- & self . units [ index]
46+ fn get_unit ( & self , index : usize ) -> & dyn ComponentUnit {
47+ & * self . units [ index]
4248 }
4349
4450 fn remove ( & mut self , index : usize ) {
You can’t perform that action at this time.
0 commit comments