Background
Let us quickly troubleshoot a rust build warning.
Error Message
Textual
>cargo build warning: field `person_name` is never read --> src\main.rs:27:7 | 25 | struct Congregant | ---------- field in this struct 26 | { 27 | person_name: String | ^^^^^^^^^^^ | = note: `Congregant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default
Image
Source Code
Code Snippet
Here is a snippet of our source code
#[derive(Debug)] struct Congregant { person_name: String , bible_translation: String , is_kjv: bool , err:String }
Error Message Review
Textual
= note: `Congregant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `#[warn(dead_code)]` on by default
= note: `#[warn(dead_code)]` on by default
Explanation
Conpiler has this to say:-
- = note: `Congregant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
- Yes, you have enabled the debug flag
- But, I will intentionally ignore the Dubug trait while checking for “dead code”
- = note: `#[warn(dead_code)]` on by default
- #[warn(dead_code)]
- Warning for dead ( unneeded ) code is on by default
- In this case, we are setting the person’s name, yet never reading it
- #[warn(dead_code)]
Remediation
Outline
- Source Code
- Added directives
- #[allow(dead_code)]
- #[allow(unused)]
- Added implementation code for structure display
- Added directives
Source Code
Remediation
Code
impl std::fmt::Display for Congregant { fn fmt ( &self, f: &mut std::fmt::Formatter ) -> std::fmt::Result { let buffer:String; buffer = format! ( "{0}\r\n\tBible Translation:- {1}\r\n\tIs KJV:- {2}\r\n\tErr:- {3}\r\n" , self.person_name , self.bible_translation , self.is_kjv , self.err ); let result = writeln! ( f , "{}" , buffer ); return result; } }
Online Code IDE
OnlineGDB
- RustKJVOnly
Link
Source Code Control
GitLab
- Rust – Exception Handling
- Link
Link - Files
- 01) RustKJVOnly.rs
- Link
Listening
Listenting to who I need to listen to:-
Dedication
This is for my __ EM from up the way.