-
Notifications
You must be signed in to change notification settings - Fork 3
Outputting stars into a properly structured markdown file #26
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,10 @@ use chrono::{DateTime, Utc}; | |
| use reqwest::header::{qitem, Accept, Authorization, Bearer, Link, RelationType, UserAgent}; | ||
| use serde_derive::Deserialize; | ||
| use std::{env, error, fmt, mem}; | ||
| use std::error::Error; | ||
| use std::io::prelude::*; | ||
| use std::fs::File; | ||
| use std::path::Path; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Config { | ||
|
|
@@ -128,6 +132,20 @@ pub fn collect_stars(config: Config) -> Result<(), Box<dyn error::Error>> { | |
| } | ||
| println!("Collected {} stars", stars.len()); | ||
|
|
||
| let path = Path::new("output.md"); | ||
| let display = path.display(); | ||
|
|
||
| let mut file = match File::create(&path) { | ||
| Err(why) => panic!("couldn't create {}: {}", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Instead of I'd recommend having a look at the |
||
| display, | ||
| why.description()), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to go looking to find the It's defined on the |
||
| Ok(file) => file, | ||
| }; | ||
|
|
||
| for star in stars.iter(){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This introduces a new loop to print each star the the buffer, but there is already a loop for printing each star to |
||
| write!(file, "{}\x20\x20\r", star); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having trouble understanding the format string here, what's the purpose of Also, careful with your line terminators, I see you're making use of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Huh, a close reading of the original Markdown spec does specify 2 spaces before a return. I'm not actually aware of any other specs that specify this - GitHub's Markdown spec says "A line is a sequence of zero or more characters other than newline (
Yup! Though |
||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
pathisn't used anywhere else, we can inline its value;File::createcan accept as an argument anything that implements theAsRef<Path>trait whichstrdoes.See the
File::createexample in the docs.