@@ -44,44 +44,33 @@ impl Histories {
44
44
Self { histories }
45
45
}
46
46
47
- // TODO: impl as From trait
48
- fn from ( histories : histories:: Histories ) -> Self {
49
- let mut result: Vec < History > = vec ! [ ] ;
50
- for h in histories. histories {
51
- result. push ( History :: from ( h) ) ;
52
- }
53
- Self { histories : result }
54
- }
55
-
56
47
pub fn into ( self ) -> histories:: Histories {
57
48
let mut result: Vec < histories:: History > = vec ! [ ] ;
58
49
for h in self . histories {
59
- result. push ( History :: into ( h ) ) ;
50
+ result. push ( h . into ( ) ) ;
60
51
}
61
52
histories:: Histories { histories : result }
62
53
}
63
54
}
64
55
56
+ impl From < histories:: Histories > for Histories {
57
+ fn from ( histories : histories:: Histories ) -> Histories {
58
+ let mut result: Vec < History > = vec ! [ ] ;
59
+ for h in histories. histories {
60
+ result. push ( History :: from ( h) ) ;
61
+ }
62
+ Self { histories : result }
63
+ }
64
+ }
65
+
65
66
#[ derive( Debug , PartialEq , Serialize , Deserialize , Clone ) ]
66
67
pub struct History {
67
68
path : PathBuf ,
68
69
commands : Vec < HistoryCommand > ,
69
70
}
70
71
71
72
impl History {
72
- // TODO: impl as From trait
73
- fn from ( history : histories:: History ) -> Self {
74
- let mut commands: Vec < HistoryCommand > = vec ! [ ] ;
75
- for h in history. commands {
76
- commands. push ( HistoryCommand :: from ( h) ) ;
77
- }
78
-
79
- History {
80
- path : history. path ,
81
- commands,
82
- }
83
- }
84
-
73
+ // Implementing From<file::toml::History> on the model::History side is not desirable due to dependency direction, so the into method is manually defined.
85
74
fn into ( self ) -> histories:: History {
86
75
let mut commands: Vec < histories:: HistoryCommand > = vec ! [ ] ;
87
76
for h in self . commands {
@@ -99,6 +88,20 @@ impl History {
99
88
}
100
89
}
101
90
91
+ impl From < histories:: History > for History {
92
+ fn from ( history : histories:: History ) -> History {
93
+ let mut commands: Vec < HistoryCommand > = vec ! [ ] ;
94
+ for h in history. commands {
95
+ commands. push ( HistoryCommand :: from ( h) ) ;
96
+ }
97
+
98
+ History {
99
+ path : history. path ,
100
+ commands,
101
+ }
102
+ }
103
+ }
104
+
102
105
/// toml representation of histories::HistoryCommand.
103
106
#[ derive( Debug , PartialEq , Serialize , Deserialize , Clone ) ]
104
107
#[ serde( rename_all = "kebab-case" ) ]
@@ -112,14 +115,6 @@ impl HistoryCommand {
112
115
Self { runner_type, args }
113
116
}
114
117
115
- // TODO: impl as From trait
116
- fn from ( command : histories:: HistoryCommand ) -> Self {
117
- Self {
118
- runner_type : command. runner_type ,
119
- args : command. args . clone ( ) ,
120
- }
121
- }
122
-
123
118
fn into ( self ) -> histories:: HistoryCommand {
124
119
histories:: HistoryCommand {
125
120
runner_type : self . runner_type ,
@@ -128,6 +123,15 @@ impl HistoryCommand {
128
123
}
129
124
}
130
125
126
+ impl From < histories:: HistoryCommand > for HistoryCommand {
127
+ fn from ( command : histories:: HistoryCommand ) -> HistoryCommand {
128
+ Self {
129
+ runner_type : command. runner_type ,
130
+ args : command. args . clone ( ) ,
131
+ }
132
+ }
133
+ }
134
+
131
135
// TODO: should return Result not Option(returns when it fails to get the home dir)
132
136
pub fn history_file_path ( ) -> Option < ( PathBuf , String ) > {
133
137
const HISTORY_FILE_NAME : & str = "history.toml" ;
0 commit comments