Rust:- Build Warning – “crate should have a snake case name” – Project Rename & Binary Rename

Background

Rust is really finicky in terms of naming convention.

Lineage

  1. Rust:- Build Warning – “crate should have a snake case name” – Workaround – Ignore
    Date Posted:- 2022-September-15th
    Link
  2. Rust:- Build Warning – “crate should have a snake case name” – Project Rename
    Date Posted:- 2022-September-15th
    Link

Error Message

Image

Text


>cargo build
   Compiling KJVOnly v0.1.0 (R:\spirituality\christianity\scripture\bible\KJVOnly)
warning: crate `KJVOnly` should have a snake case name
  |
  = help: convert the identifier to snake case: `kjvonly`
  = note: `#[warn(non_snake_case)]` on by default

warning: `KJVOnly` (bin "KJVOnly") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.67s

Troubleshooting

Outline

  1. Project Creation
  2. Manifest File ( Cargo.toml )

Project Creation

Here is the command we used to create the project.

Text


cargo new KJVOnly --bin

Manifest File ( Cargo.toml )

Running “cargo new” created a manifest file.

Here is what it looks like.

Text


[package]
name = "KJVOnly"
version = "0.1.0"
edition = "2021"

Explanation

The project’s name is reflected in the package section; under name.

Naming Convention

Camel Case

Wikipedia

Link

Camel case (sometimes stylized as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation. It indicates the separation of words with a single capitalized letter, and the first word starting with either case. Common examples include “iPhone” and “eBay”. It is also sometimes used in online usernames such as “johnSmith”, and to make multi-word domain names more legible, for example in promoting “EasyWidgetCompany.com”.

Camel case is often used as a naming convention in computer programming, but is an ambiguous definition due to the optional capitalization of the first letter. Some programming styles prefer camel case with the first letter capitalised, others not.  For clarity, this article calls the two alternatives upper camel case (initial uppercase letter, also known as Pascal case or bumpy case) and lower camel case (initial lowercase letter, also known as dromedary case). Some people and organizations, notably Microsoft, use the term camel case only for lower camel case, designating Pascal case for the upper camel case.

Workaround

Outline

  1. Project
    • Rename
    • Clean
    • Build
  2. Binary File
    • Rename

Project

Rename Project

Outline

  1. Project
    • Rename
      • Rename project from KJVOnly to kjvonly
      • The change needs to be applied to the manifest file ( Cargo.toml )

Cargo.toml

Text

[package]

#name = "KJVOnly"
name = "kjvonly"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]


Clean Project

Outline

  1. Project
    • Clean
      • Clean Project
        • When a rust project is built, files are created based on what is in the manifest file
        • Let us remove files created from previous build by issuing “cargo clean“.

Command

Syntax

cargo clean

Sample

cargo clean

Output

Image

Text
>cargo clean

>

Build

cargo build

Outline

  1. Project
    • Build
      • Build Project
        • Let us re-build the project

Syntax


cargo build

Sample


cargo build --release --quiet

Output

Image

Text

>cargo build --release --quiet

>

Explanation

We have a clean build.

 

Binary File

Binary File Rename

Outline

  1. Using Powershell let us rename our output file
    • Microsoft.PowerShell.Management
      • Rename-Item
        • Use -Path or -LiteralPath
        • Use -NewName
        • Use -Force

build.cmd

Source File

setlocal

Rem Set Folder and File names

set "folderDebug=target\debug"

set "folderRelease=target\release"

set "binaryCurrent=kjvonly.exe"

set "binaryTarget=KJVonly.exe"

set "binaryCurrentFullDebug=%folderDebug%\%binaryCurrent%"

set "binaryCurrentFullRelease=%folderRelease%\%binaryCurrent%"

REM Remove previous build binary files

cargo clean

REM Build Debug

cargo  build

REM Build Release

cargo  build --release

Rem Rename Debug binary file

If exist %binaryCurrentFullDebug% Powershell -Command "Rename-Item -Path %binaryCurrentFullDebug% -NewName %binaryTarget% -Force"

Rem Rename Release binary file

If exist %binaryCurrentFullRelease% Powershell -Command "Rename-Item -Path %binaryCurrentFullRelease% -NewName %binaryTarget% -Force"

endlocal

Output
Textual

>build

>setlocal

>Rem Set Folder and File names

>set "folderDebug=target\debug"

>set "folderRelease=target\release"

>set "binaryCurrent=kjvonly.exe"

>set "binaryTarget=KJVonly.exe"

>set "binaryCurrentFullDebug=target\debug\kjvonly.exe"

>set "binaryCurrentFullRelease=target\release\kjvonly.exe"

>REM Remove previous build binary files

>cargo clean

>REM Build Debug

>cargo  build
   Compiling kjvonly v0.1.0 (R:\spirituality\christianity\scripture\bible\KJVOnly)
    Finished dev [unoptimized + debuginfo] target(s) in 0.46s

>REM Build Release

>cargo  build --release
   Compiling kjvonly v0.1.0 (R:\spirituality\christianity\scripture\bible\KJVOnly)
    Finished release [optimized] target(s) in 0.38s

>Rem Rename Debug binary file

>If exist target\debug\kjvonly.exe Powershell -Command "Rename-Item -Path target\debug\kjvonly.exe -NewName KJVonly.exe -Force"

>Rem Rename Release binary file

>If exist target\release\kjvonly.exe Powershell -Command "Rename-Item -Path target\release\kjvonly.exe -NewName KJVonly.exe -Force"

>endlocal

>

 

Image

 

Source Code Control

GitLab

  1. Rust – Exception Handling
    • Link
      Link
    • Files
      • RustKJVOnlyBuild.cmd

References

  1. Microsoft
    • Learn > PowerShell >  Reference > Microsoft.PowerShell.Management

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s