Skip to content

Commit

Permalink
Generalize function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Jan 12, 2020
1 parent c2fec13 commit 10c612f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* https://www.cyberciti.biz/tips/top-linux-monitoring-tools.html
* http://www.brendangregg.com/USEmethod/use-linux.html
* [ ] Re-work API
* [ ] https://github.com/rust-lang/api-guidelines
* [X] https://github.com/rust-lang/api-guidelines
* [ ] https://rust-lang.github.io/api-guidelines/flexibility.html#functions-minimize-assumptions-about-parameters-by-using-generics-c-generic
* [ ] https://deterministic.space/elegant-apis-in-rust.html
* [X] https://deterministic.space/elegant-apis-in-rust.html
* [ ] Activate deny missing docs and add docs
* [ ] https://rust-lang.github.io/api-guidelines/documentation.html

12 changes: 6 additions & 6 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ impl Command {
}

/// Set title of command
pub fn with_timeout(self, timeout_sec: u64) -> Command {
pub fn with_timeout<T: Into<Option<u64>>>(self, timeout_sec: T) -> Command {
Command {
timeout_sec: Some(timeout_sec),
timeout_sec: timeout_sec.into(),
..self
}
}

/// Set description of command
pub fn with_description<T: Into<String>>(self, description: T) -> Command {
pub fn with_description<T: Into<String>, S: Into<Option<T>>>(self, description: S) -> Command {
Command {
description: Some(description.into()),
description: description.into().map(Into::into),
..self
}
}

/// Set Links of command
pub fn with_links(self, links: Vec<Link>) -> Command {
pub fn with_links<T: Into<Option<Vec<Link>>>>(self, links: T) -> Command {
Command {
links: Some(links),
links: links.into(),
..self
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ impl Profile {
Self::new_with_description(name, commands, None)
}

pub fn new_with_description<T: Into<String> + Clone>(name: T, commands: &[T], description: Option<T>) -> Profile {
pub fn new_with_description<T: Into<String> + Clone, S: Into<Option<T>>>(name: T, commands: &[T], description: S) -> Profile {
let name = name.into();
let commands = commands.clone().to_vec().into_iter().map(Into::into).collect();
let description = description.map(Into::into);
let description = description.into().map(Into::into);

Profile {
name,
Expand Down
4 changes: 2 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub mod thread {
impl ThreadRunner {
pub fn new() -> Self { ThreadRunner::default() }

pub fn with_progress(self, progress_tx: Sender<usize>) -> Self {
pub fn with_progress<T: Into<Option<Sender<usize>>>>(self, progress_tx: T) -> Self {
ThreadRunner {
progress_tx: Some(progress_tx),
progress_tx: progress_tx.into(),
}
}

Expand Down

0 comments on commit 10c612f

Please sign in to comment.