Error codes

E0121: private field

In a terminal: auk explain E0121 prints this page.

On this page

A pub struct's fields are public, except fields whose type is private to its module, and the fields of a non-pub struct. This code outside the module read or wrote such a field.

Wrong#

toml
[package]
name = "app"
version = "0.1.0"
auk
struct Secret { code: int }
pub struct Item { name: str, s: Secret }
pub fn make(): Item = Item { name: "auk", s: Secret { code: 7 } }
auk
fn main() { print(shop.make().s) }

Fixed#

auk
fn main() { print(shop.make().name) }

Common causes#

  • A field whose type is private: make the type pub, or expose a function that returns what callers need.
  • Destructuring a struct from another module with a pattern that names a private field.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page