struct Output;
impl Output {
fn new() -> Self {
Self
}
fn clear_screen() -> crossterm::Result<()> {
execute!(stdout(), terminal::Clear(ClearType::All))
}
fn refresh_screen(&self) -> crossterm::Result<()> {
Self::clear_screen()
}
}
looks good to me.
The concept of "used" that the unused item warnings use is transitive, in that they only consider things "used" if they are used by things that are themselves used (or items accessible from outside the crate, and fn main
); if you never call Output::new
, then you never construct Output
, so you will get a warning for both.
4 Likes
you mean its associated function ?
jhpratt
October 11, 2021, 3:02am
#4
Please stop posting in all bold: it's wholly unnecessary.
No instance of Output
is ever actually constructed in any possible execution path. As such, the lint is triggered.
1 Like
The example compiles to a no-op because there is no main
and no public data structures or methods.
Try
pub struct Output;
impl Output {
pub fn new() -> Self {
Self
}
pub fn clear_screen() -> crossterm::Result<()> {
execute!(stdout(), terminal::Clear(ClearType::All))
}
pub fn refresh_screen(&self) -> crossterm::Result<()> {
Self::clear_screen()
}
}
system
closed
January 9, 2022, 3:32am
#6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.