Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove command parser arguments From implementation #763

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions command-parser/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ pub struct Arguments<'a> {
impl<'a> Arguments<'a> {
/// Returns a new iterator of arguments from a buffer.
pub fn new(buf: &'a str) -> Self {
Self::from(buf)
Self {
buf: buf.trim(),
indices: buf.trim().char_indices(),
idx: 0,
}
}

/// Returns a view of the underlying buffer of arguments.
Expand Down Expand Up @@ -63,16 +67,6 @@ impl<'a> Arguments<'a> {
}
}

impl<'a> From<&'a str> for Arguments<'a> {
fn from(buf: &'a str) -> Self {
Self {
buf: buf.trim(),
indices: buf.trim().char_indices(),
idx: 0,
}
}
}

impl<'a> Debug for Arguments<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.debug_struct("Arguments")
Expand Down Expand Up @@ -139,11 +133,11 @@ mod tests {
use static_assertions::assert_impl_all;
use std::fmt::Debug;

assert_impl_all!(Arguments<'_>: Clone, Debug, From<&'static str>, Iterator, Send, Sync);
assert_impl_all!(Arguments<'_>: Clone, Debug, Iterator, Send, Sync);

#[test]
fn test_as_str() {
let args = Arguments::from("foo bar baz");
let args = Arguments::new("foo bar baz");
assert_eq!("foo bar baz", args.as_str());
}

Expand Down