Skip to content

Commit

Permalink
Add new() constructor that creates an empty sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
giancosta86 committed Apr 14, 2024
1 parent c8e5d3a commit 45b7b97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "digit-sequence"
version = "0.3.1"
version = "0.3.2"

authors = ["Gianluca Costa <gianluca@gianlucacosta.info>"]
edition = "2021"
Expand Down
16 changes: 15 additions & 1 deletion src/digit_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::fmt::Display;
///
/// # Creation
///
/// A digit sequence can be created via *conversions* - which are not always *infallible*.
/// A digit sequence is usually created via *conversions* - which are not always *infallible*; a [constructor](DigitSequence::new) is also provided to instantiate
/// an empty sequence.
///
/// ## Infallible conversions
///
Expand Down Expand Up @@ -187,6 +188,19 @@ pub fn internal_create_digit_sequence(digits: Vec<u8>) -> DigitSequence {
}

impl DigitSequence {
/// Creates an empty DigitSequence
///
/// ```
/// use digit_sequence::DigitSequence;
///
/// let sequence = DigitSequence::new();
///
/// assert_eq!(sequence.iter().len(), 0);
/// ```
pub fn new() -> DigitSequence {
DigitSequence(vec![])
}

/// Convenience method for iterating over references to the digits.
pub fn iter(&self) -> std::slice::Iter<u8> {
self.0.iter()
Expand Down

0 comments on commit 45b7b97

Please sign in to comment.