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 24, 2024
1 parent 6782f5f commit 6a13436
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 97 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
88 changes: 0 additions & 88 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 Expand Up @@ -155,35 +96,6 @@ fn load_pgpwords() -> Vec<Vec<String>> {
vec![even_words, odd_words]
}

/// Creates a default `Wordlist` with a specified number of words.
///
/// This function generates a `Wordlist` using the PGP word list, which is a standardized
/// list of words often used for secure and human-readable encoding.
///
/// # Arguments
///
/// * `num_words` - The number of words that should be in a complete wormhole code.
///
/// # Returns
///
/// Returns a `Wordlist` instance initialized with the PGP word list and the specified
/// number of words.
///
/// # Examples
///
/// ```
/// use your_crate_name::default_wordlist;
///
/// let wordlist = default_wordlist(3);
/// assert_eq!(wordlist.num_words, 3);
/// assert_eq!(wordlist.words.len(), 2); // PGP word list has two lists (even and odd)
/// ```
///
/// # Note
///
/// The PGP word list consists of two lists of 256 words each: one for even positions
/// and one for odd positions in the code. This function uses these lists regardless
/// of the `num_words` specified.
pub fn default_wordlist(num_words: usize) -> Wordlist {
Wordlist {
num_words,
Expand Down

0 comments on commit 6a13436

Please sign in to comment.