Skip to content

Commit

Permalink
Pass jobs as Option<&str> rather than Option<String>
Browse files Browse the repository at this point in the history
  • Loading branch information
twe4ked committed May 5, 2020
1 parent f2f5467 commit 82cab91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
20 changes: 5 additions & 15 deletions src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Component {
fn components_from_token(
token: Token,
shell: &Shell,
jobs: &Option<String>,
jobs: Option<&str>,
status: usize,
) -> Result<Vec<Option<Component>>> {
let mut ret = Vec::new();
Expand Down Expand Up @@ -55,20 +55,10 @@ fn components_from_token(
Condition::LastCommandStatus => status == 0,
};
if result {
ret.append(&mut components_from_tokens(
left,
shell,
jobs.clone(),
status,
)?);
ret.append(&mut components_from_tokens(left, shell, jobs, status)?);
} else {
if let Some(right) = right {
ret.append(&mut components_from_tokens(
right,
shell,
jobs.clone(),
status,
)?);
ret.append(&mut components_from_tokens(right, shell, jobs, status)?);
}
}
}
Expand All @@ -80,13 +70,13 @@ fn components_from_token(
pub fn components_from_tokens(
tokens: Vec<Token>,
shell: &Shell,
jobs: Option<String>,
jobs: Option<&str>,
status: usize,
) -> Result<Vec<Option<Component>>> {
let mut components = Vec::new();

for token in tokens.into_iter() {
let mut c = components_from_token(token, shell, &jobs, status)?;
let mut c = components_from_token(token, shell, jobs, status)?;
components.append(&mut c);
}

Expand Down
4 changes: 2 additions & 2 deletions src/component/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::component::Component;

pub fn display(jobs: Option<String>) -> Option<Component> {
pub fn display(jobs: Option<&str>) -> Option<Component> {
match jobs {
Some(jobs) => Some(Component::Computed(jobs)),
Some(jobs) => Some(Component::Computed(jobs.to_owned())),
None => None,
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn components(
) -> Result<Vec<component::Component>> {
let tokens = parser::parse(config)?;

let components = component::components_from_tokens(tokens, shell, jobs, status)?;
let components = component::components_from_tokens(tokens, shell, jobs.as_deref(), status)?;

Ok(component::squash(components))
}

0 comments on commit 82cab91

Please sign in to comment.