Skip to content

circular-buffer: Added template to the stub file#608

Merged
petertseng merged 2 commits intoexercism:masterfrom
ZapAnton:circular_buffer_template
Aug 26, 2018
Merged

circular-buffer: Added template to the stub file#608
petertseng merged 2 commits intoexercism:masterfrom
ZapAnton:circular_buffer_template

Conversation

@ZapAnton
Copy link
Copy Markdown
Contributor

@ZapAnton ZapAnton commented Aug 7, 2018

Contributes to the #551

It is unclear what write method should return on success, so the return type is Result<(), Error>.

Perhaps () could be replaced with usize as to indicate the index of the successful write?

Comment thread exercises/circular-buffer/src/lib.rs Outdated
FullBuffer,
}

impl<T: Debug> CircularBuffer<T> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as with sublist - I know that this Debug constraint is added purely so that we can reference variables in unimplemented message. We made a different choice in c5f7a43 and I'll consider whether it's better to use underscore prefix here. Input appreciated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should not bound T: Debug here, and instead use an underscore variable. Perhaps it's worth identifying which of the exercises first uses an underscore variable in the track and adding a comment explaining why that is used, instead of a Debug trait bound.

Comment thread exercises/circular-buffer/src/lib.rs Outdated
);
}

pub fn write(&mut self, element: T) -> Result<(), Error> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Result<(), Error> makes sense and is the accepted way, as https://doc.rust-lang.org/std/io/trait.Write.html#method.write_all does this as well. While it would be possible to return the index of the inserted value, I think the API presented in this exercise is not conducive to a client of this code being able to do anything with that information, so I wouldn't add it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree: Result<(), Error> is fine and idiomatic.

@petertseng petertseng merged commit 370007d into exercism:master Aug 26, 2018
@ZapAnton ZapAnton deleted the circular_buffer_template branch August 26, 2018 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants