Rust

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.

Donald Le
1 min readSep 22, 2020

--

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.

~~PEACE~~

--

--

Donald Le
Donald Le

Written by Donald Le

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

No responses yet