Skip to content

Commit

Permalink
⬆️ Upgrade to Rust 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
codeworm96 committed Dec 30, 2018
1 parent b6c6aaa commit 306919c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "dy-weekly-generator"
version = "0.2.3"
authors = ["codeworm96 <[email protected]>"]
edition = "2018"

[[bin]]
name = "weekly-gen"
Expand Down
13 changes: 5 additions & 8 deletions src/bin/weekly-gen.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
extern crate dy_weekly_generator;
use std::fs::File;
use std::io;

use clap::{load_yaml, App};

use dy_weekly_generator::casual::Casual;
use dy_weekly_generator::error::Error;
use dy_weekly_generator::formal::Formal;
use dy_weekly_generator::github;
use dy_weekly_generator::weekly::WeeklyBuilder;

#[macro_use]
extern crate clap;
use clap::App;

use std::fs::File;
use std::io;

fn work() -> Result<(), Error> {
let yaml = load_yaml!("cli.yml");
let matches = App::from_yaml(yaml).get_matches();
Expand Down
7 changes: 4 additions & 3 deletions src/casual.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::io;

use lazy_static::lazy_static;
use regex::Regex;

use error::Error;
use weekly::Extractor;
use crate::error::Error;
use crate::weekly::Extractor;

pub struct Casual {
entries: Vec<String>,
Expand All @@ -29,7 +30,7 @@ impl Extractor for Casual {
res
}

fn render(&self, out: &mut io::Write) -> Result<(), Error> {
fn render(&self, out: &mut dyn io::Write) -> Result<(), Error> {
for entry in &self.entries {
// Add a horizontal line between the entries.
write!(out, "{}\n\n***\n\n", entry)?
Expand Down
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io;

use json;
use reqwest;
use std::io;

pub enum Error {
ConfigErr,
Expand Down
9 changes: 5 additions & 4 deletions src/formal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use std::collections::HashMap;
use std::io;
use std::mem;

use lazy_static::lazy_static;
use regex::Regex;
use yaml_rust::YamlLoader;

use error::Error;
use weekly::Extractor;
use crate::error::Error;
use crate::weekly::Extractor;

enum EntryType {
Draft,
Expand Down Expand Up @@ -103,7 +104,7 @@ impl Entry {
self.cc.append(&mut other.cc);
}

fn render(&self, out: &mut io::Write) -> Result<(), Error> {
fn render(&self, out: &mut dyn io::Write) -> Result<(), Error> {
write!(out, "- ")?;
match self.link.as_ref() {
Some(link) => write!(out, "[{}]({})", self.name, link)?,
Expand Down Expand Up @@ -184,7 +185,7 @@ impl Extractor for Formal {
res
}

fn render(&self, out: &mut io::Write) -> Result<(), Error> {
fn render(&self, out: &mut dyn io::Write) -> Result<(), Error> {
for entry in self.entries.values() {
entry.render(out)?;
}
Expand Down
13 changes: 7 additions & 6 deletions src/github.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use std::io::Read;
use std::mem;

use json;
use lazy_static::lazy_static;
use regex::Regex;
use reqwest;
use reqwest::header::{HeaderMap, ACCEPT, AUTHORIZATION, LINK, USER_AGENT};
use reqwest::Client;

use std::io::Read;
use std::mem;

use error::Error;
use crate::error::Error;

const API_ROOT: &'static str = "https://api.github.com";

pub struct Comments<'a> {
client: Client,
key: Option<&'a str>,
comments: Box<Iterator<Item = String>>,
comments: Box<dyn Iterator<Item = String>>,
next: Option<String>,
}

Expand Down Expand Up @@ -42,7 +43,7 @@ impl<'a> Iterator for Comments<'a> {
}

struct Page {
comments: Box<Iterator<Item = String>>,
comments: Box<dyn Iterator<Item = String>>,
next: Option<String>,
}

Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
extern crate json;
extern crate regex;
extern crate reqwest;
extern crate yaml_rust;

#[macro_use]
extern crate lazy_static;

pub mod casual;
pub mod error;
pub mod formal;
Expand Down
14 changes: 7 additions & 7 deletions src/weekly.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::io;

use error::Error;
use crate::error::Error;

pub trait Extractor {
fn extract(&mut self, &str) -> bool;
fn render(&self, &mut io::Write) -> Result<(), Error>;
fn extract(&mut self, _: &str) -> bool;
fn render(&self, _: &mut dyn io::Write) -> Result<(), Error>;
}

pub struct WeeklyBuilder {
extractors: Vec<Box<Extractor>>,
extractors: Vec<Box<dyn Extractor>>,
}

pub struct Weekly {
extractors: Vec<Box<Extractor>>,
extractors: Vec<Box<dyn Extractor>>,
}

impl WeeklyBuilder {
Expand All @@ -22,7 +22,7 @@ impl WeeklyBuilder {
}
}

pub fn add_extractor(mut self, extractor: Box<Extractor>) -> Self {
pub fn add_extractor(mut self, extractor: Box<dyn Extractor>) -> Self {
self.extractors.push(extractor);
self
}
Expand All @@ -43,7 +43,7 @@ impl Weekly {
}
}

pub fn render(&self, out: &mut io::Write) -> Result<(), Error> {
pub fn render(&self, out: &mut dyn io::Write) -> Result<(), Error> {
let header = r#"---
layout: post
title: Weekly
Expand Down

0 comments on commit 306919c

Please sign in to comment.