Import Struct in Rust

By default, Struct is private when using in different module. This post will show example for importing struct from different module.

Photo by Ahmad Qime on Unsplash

Define a public struct for all fields in the struct.

If we only define pub struct, and not for the field, the field will be automatically be private. So in the case if you want to access the field directly, you would need to define the field as pub also.

Calling the pub struct from different directory for the test file.

Hope it helps.


A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store