-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds alphanumeric name generator
- Loading branch information
1 parent
106a12b
commit 258cb33
Showing
5 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! Services for various functionality within the execution engine. | ||
|
||
pub mod name; | ||
pub mod runner; | ||
|
||
pub use runner::Runner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Name generation services. | ||
|
||
use rand::rngs::ThreadRng; | ||
use rand::Rng as _; | ||
|
||
/// A name generator. | ||
pub trait Generator { | ||
/// Generates a new name. | ||
fn generate(&self) -> String; | ||
} | ||
|
||
/// An alphanumeric name generator. | ||
pub struct Alphanumeric { | ||
/// The length of the randomized portion of the name. | ||
length: usize, | ||
} | ||
|
||
impl Default for Alphanumeric { | ||
fn default() -> Self { | ||
Self { length: 12 } | ||
} | ||
} | ||
|
||
impl Generator for Alphanumeric { | ||
fn generate(&self) -> String { | ||
let mut rng = ThreadRng::default(); | ||
|
||
let random: String = (&mut rng) | ||
.sample_iter(&rand::distributions::Alphanumeric) | ||
.take(self.length) // Generate 12 alphanumeric characters | ||
.map(char::from) | ||
.collect(); | ||
|
||
format!("job-{}", random) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,6 @@ impl Runner { | |
}; | ||
|
||
self.tasks.push(Box::pin(fun)); | ||
|
||
TaskHandle { callback: rx } | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters