Why the compiler keeps telling me that this const is not used?

Hi all,

I keep getting these warnings where I defined a constant referenced it and the compiler tell's me that the constant is not used why?

You can see in the code below that the constant is used. At first rust-analyser warned me to make the the constant public don't know why

pub const IP_HDR_LEN_POS: usize = 0x0e;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct PacketRef {
    pub ts_sec: u32,
    pub ts_usec: u32,
    pub inc_len: u32,
    pub orig_len: u32,
    pub header_only: bool,
    raw_packet: Vec<u8>,
    vo: usize,

impl PacketRef {

    pub fn _get_ip_header_len(&self) -> u8 {
          let hdr_len = self.raw_packet[IP_HDR_LEN_POS];
          (hdr_len >> 4) * 4

If all of the functions that use a const are unused, the const itself will still be considered unused


I know but the function is used!

Is the function that uses it used?

1 Like

Or is your module private?


That's it module was private... thank you.

1 Like

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.