Skip to content

Commit

Permalink
removed temporary documentation, fixed clippy::never_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelPanic0x committed Sep 23, 2024
1 parent 6782f5f commit dedf39a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 68 deletions.
16 changes: 7 additions & 9 deletions cli/src/reedline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,13 @@ pub fn enter_code() -> eyre::Result<String> {

let prompt = CodePrompt::default();

loop {
let sig = line_editor.read_line(&prompt);
match sig {
Ok(Signal::Success(buffer)) => return Ok(buffer),
// TODO: fix temporary work around
Ok(Signal::CtrlC) => bail!("Ctrl-C received"),
Ok(Signal::CtrlD) => bail!("Ctrl-D received"),
Err(e) => bail!(e),
}
let sig = line_editor.read_line(&prompt);
match sig {
Ok(Signal::Success(buffer)) => return Ok(buffer),
// TODO: fix temporary work around
Ok(Signal::CtrlC) => bail!("Ctrl-C received"),
Ok(Signal::CtrlD) => bail!("Ctrl-D received"),
Err(e) => bail!(e),
}
}

Expand Down
59 changes: 0 additions & 59 deletions src/core/wordlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ use rand::{rngs::OsRng, seq::SliceRandom};
use serde_json::{self, Value};
use std::fmt;

/// Represents a collection of word lists used for generating and completing wormhole codes.
///
/// The `Wordlist` struct contains multiple lists of words and information about
/// how many words should be in a complete wormhole code.
#[derive(PartialEq)]
pub struct Wordlist {
/// The number of words that should be in a complete wormhole code.
pub num_words: usize,
/// A vector of word lists. Each inner vector represents a distinct list of words.
pub words: Vec<Vec<String>>,
}

Expand All @@ -26,35 +20,6 @@ impl Wordlist {
Wordlist { num_words, words }
}

/// Returns a list of word completions based on the given prefix.
///
/// This method generates completions for a partial wormhole code. It takes into account
/// the number of dashes in the prefix to determine which word list to use for completions.
///
/// # Arguments
///
/// * `prefix` - A string slice that holds the partial wormhole code to complete.
///
/// # Returns
///
/// A vector of Strings containing all possible completions.
///
/// # Behavior
///
/// - The method cycles through word lists based on the number of dashes in the prefix.
/// - It completes the last partial word in the prefix.
/// - If the completion isn't for the last word in the code, it appends a dash.
/// - The returned completions are sorted alphabetically.
///
/// # Examples
///
/// ```
/// use your_crate_name::WordList;
///
/// let wordlist = WordList::new();
/// let completions = wordlist.get_completions("7-ze");
/// assert!(completions.contains(&"7-zebra-".to_string()));
/// ```
#[allow(dead_code)] // TODO make this API public one day
pub fn get_completions(&self, prefix: &str) -> Vec<String> {
let count_dashes = prefix.matches('-').count();
Expand Down Expand Up @@ -90,30 +55,6 @@ impl Wordlist {
completions
}

/// Generates a random wormhole code.
///
/// This method creates a new wormhole code by randomly selecting words from the word lists.
/// It ensures that the generated code has the correct number of words as specified by `num_words`.
///
/// # Returns
///
/// A String containing the randomly generated wormhole code, with words separated by dashes.
///
/// # Behavior
///
/// - Uses the OS's random number generator for secure randomness.
/// - Cycles through the word lists if `num_words` is greater than the number of available lists.
/// - Joins the selected words with dashes to form the final code.
///
/// # Examples
///
/// ```
/// use your_crate_name::WordList;
///
/// let wordlist = WordList::new();
/// let code = wordlist.choose_words();
/// assert_eq!(code.split('-').count(), wordlist.num_words());
/// ```
pub fn choose_words(&self) -> String {
let mut rng = OsRng;
let components: Vec<String> = self
Expand Down

0 comments on commit dedf39a

Please sign in to comment.