I am a newbie at rust programming. Here I was developing a FLTK app using rust. I am getting the following warning.
warning: field is never read: `group`
--> src\views\logo.rs:13:5
|
13 | group: fltk::group::Group,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
Why is it showing the warning: field is never read: group
? Is there some option resolve this warning?
my code is this:
use fltk::{image::*,
frame::Frame,
group::Group,
enums::Color,
// enums::Align,
};
use fltk::prelude::*;
use std::fs::read;
pub struct LogoImage {
group: fltk::group::Group,
// // button: fltk::button::Button,
// logo_frame: Frame,
}
impl LogoImage {
pub fn new(x:i32, y:i32, w:i32, h:i32, label:&'static str) -> LogoImage {
let mut group = Group::new(x, y, w, h, label);
group.set_align(fltk::enums::Align::Center);
group.set_frame(fltk::enums::FrameType::FlatBox);
group.set_color(fltk::enums::Color::Red);
// group.set_type(fltk::group::PackType::Horizontal);
let mut logo_frame = Frame::default()
// .with_size(w, h)
.with_size(group.width(), group.height())
.center_of(&group)
.with_label("H");
logo_frame.set_frame(fltk::enums::FrameType::FlatBox);
logo_frame.set_color(Color::Yellow);
logo_frame.draw(|f| {
// let image_data = read("assets\\app_icon.png").unwrap();
let mut img = PngImage::load("assets\\app_icon.png").unwrap();
img.scale(f.w(), f.h(), true, true);
img.draw(f.x(), f.y(), f.w(), f.h());
});
group.end();
LogoImage {group} // , logo_frame
}
}
Can some explain me this and give a solution as well (prefer solution in code not in just explanation)?
Make the internals (internal variables) of the struct either intentionally starting with _
(ie., _group
) to avoid warning or use pub in front of the internal variable (ie., pub group ...
) and use it in another rs file.
Answer:
use fltk::{image::*,
frame::Frame,
group::Group,
enums::Color,
// enums::Align,
};
use fltk::prelude::*;
use std::fs::read;
pub struct LogoImage {
_group: fltk::group::Group, // or pub group: .......
}
impl LogoImage {
pub fn new(x:i32, y:i32, w:i32, h:i32, label:&'static str) -> LogoImage {
let mut group = Group::new(x, y, w, h, label);
group.set_align(fltk::enums::Align::Center);
group.set_frame(fltk::enums::FrameType::FlatBox);
group.set_color(fltk::enums::Color::Red);
// group.set_type(fltk::group::PackType::Horizontal);
let mut logo_frame = Frame::default()
// .with_size(w, h)
.with_size(group.width(), group.height())
.center_of(&group)
.with_label("H");
logo_frame.set_frame(fltk::enums::FrameType::FlatBox);
logo_frame.set_color(Color::Yellow);
logo_frame.draw(|f| {
// let image_data = read("assets\\app_icon.png").unwrap();
let mut img = PngImage::load("assets\\app_icon.png").unwrap();
img.scale(f.w(), f.h(), true, true);
img.draw(f.x(), f.y(), f.w(), f.h());
});
group.end();
LogoImage {group} // , logo_frame
}
}