aboutsummaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
Diffstat (limited to 'posts')
-rw-r--r--posts/gripes_with_go.md21
1 files changed, 18 insertions, 3 deletions
diff --git a/posts/gripes_with_go.md b/posts/gripes_with_go.md
index 60aabc8..9bcaabc 100644
--- a/posts/gripes_with_go.md
+++ b/posts/gripes_with_go.md
@@ -166,12 +166,27 @@ employed by Rust as well:
166// 1. error handling is compulsory 166// 1. error handling is compulsory
167// 2. errors are propagated with the `?` operator 167// 2. errors are propagated with the `?` operator
168fn foo() -> Result<String, io::Error> { 168fn foo() -> Result<String, io::Error> {
169 let mut f = File::open("foo.txt")?; // return here if error 169 let mut f = File::open("foo.txt")?; // return if error
170 let mut s = String::new(); 170 let mut s = String::new();
171 171
172 f.read_to_string(&mut s)?; // return here if error 172 f.read_to_string(&mut s)?; // return if error
173 173
174 Ok(s) // all good, return the value inside a `Result` context 174 Ok(s) // all good, return a string inside a `Result` context
175}
176
177fn main() {
178 // `contents` is an enum known as Result:
179 let contents = foo();
180 match contents {
181 Ok(c) => println!(c),
182 Err(e) => eprintln!(e)
183 }
175} 184}
176``` 185```
177 186
187### Conclusion
188
189I did not want to conclude without talking about stylistic
190choices, lack of metaprogramming, bizzare export rules, but,
191I am too busy converting my `interface{}` types into actual
192generic code for Go v2.