Skip to content

Commit

Permalink
Merge pull request #2 from Integralist/integralist/move-not-reference
Browse files Browse the repository at this point in the history
refactor: move filters not pass a ref
  • Loading branch information
Integralist authored Dec 31, 2023
2 parents 08a8e9c + 87e0516 commit 45a9f2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn exec(args: Args, output: &mut (dyn Write)) -> Result<()> {
let resp = reqwest::blocking::get(&args.url)
.with_context(|| format!("Failed to GET: {}", &args.url))?;

let mut headers = Headers::new(resp.headers(), &args.filter, output);
let mut headers = Headers::new(resp.headers(), args.filter, output);
headers.parse()?.display(args.json, resp.status())?;

Ok(())
Expand Down
16 changes: 6 additions & 10 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ use reqwest::StatusCode;
use std::collections::BTreeMap;
use std::io::{BufWriter, Write};

pub struct Headers<'a, 'b, 'c> {
filters: &'b Option<String>,
pub struct Headers<'a, 'b> {
filters: Option<String>,
map: &'a HeaderMap,
output: &'c mut (dyn Write),
output: &'b mut (dyn Write),
}

impl<'a, 'b, 'c> Headers<'a, 'b, 'c> {
pub fn new(
map: &'a HeaderMap,
filters: &'b Option<String>,
output: &'c mut (dyn Write),
) -> Self {
impl<'a, 'b> Headers<'a, 'b> {
pub fn new(map: &'a HeaderMap, filters: Option<String>, output: &'b mut (dyn Write)) -> Self {
Self {
filters,
map,
Expand All @@ -29,7 +25,7 @@ impl<'a, 'b, 'c> Headers<'a, 'b, 'c> {
pub fn parse(&mut self) -> Result<Parsed> {
let mut filters: Vec<regex::Regex> = Vec::new();

if let Some(f) = self.filters {
if let Some(f) = &self.filters {
filters = f
.split(',')
.map(|f| Regex::new(format!("(?i){f}").as_str()).unwrap())
Expand Down

0 comments on commit 45a9f2d

Please sign in to comment.