File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -142,19 +142,13 @@ fn load_portfolio() -> Option<Portfolio> {
142
142
// get the filename and read the file
143
143
let filename = prompt ( "Enter filename to load: " ) ;
144
144
let data = fs:: read_to_string ( filename) ;
145
-
146
- let raw_portfolio: String ;
147
- if data. is_ok ( ) {
148
- raw_portfolio = data. unwrap ( ) ;
149
- } else {
150
- return None ;
151
- } ;
145
+ let raw_portfolio: String = if let Ok ( x) = data { x } else { return None } ;
152
146
153
147
// convert the read file into an actual Portfolio struct
154
148
let portfolio = serde_json:: from_str ( & raw_portfolio) ;
155
149
156
- if portfolio . is_ok ( ) {
157
- Some ( portfolio . unwrap ( ) )
150
+ if let Ok ( x ) = portfolio {
151
+ Some ( x )
158
152
} else {
159
153
None
160
154
}
@@ -163,9 +157,8 @@ fn load_portfolio() -> Option<Portfolio> {
163
157
fn dump_portfolio ( portfolio : & Portfolio ) {
164
158
let json = serde_json:: to_string ( & portfolio) ;
165
159
let filename = prompt ( "Enter filename to dump assets to: " ) ;
166
- if json. is_ok ( ) {
167
- //println!("{}", json.unwrap())
168
- let result = fs:: write ( filename, json. unwrap ( ) ) ;
160
+ if let Ok ( x) = json {
161
+ let result = fs:: write ( filename, x) ;
169
162
if result. is_err ( ) {
170
163
println ! ( "Error occurred when dumping. Portfolio not dumped." ) ;
171
164
}
You can’t perform that action at this time.
0 commit comments