liveBook · Manning

Dotted notation

As explained in Learn Rust in a Month of Lunches

Dot notation is Rust syntax that accesses a tuple element or object member by placing a period before its selector.

Dotted notation, also called the dot operator, uses a period to select a tuple item or access a type's member or method. Tuple items use numbers after the dot, such as random_tuple.0. section 3.1.3 section 4.3

Use the dot operator in several closely related ways:

  • Select tuple elements with positions beginning at 0: random_tuple.0, random_tuple.1, and so on. section 3.1.3
  • Call methods with value.method(), as in my_name.is_empty(). Rust automatically dereferences references as needed to find the original type. section 4.3
  • Access struct fields through a reference with expressions such as person.name and person.happiness. section 4.2

Calling a method through references

A String reference normally requires dereferencing before reaching the value. However, a double reference can call the method directly: let double_ref = &&my_name; println!("{}", double_ref.is_empty());. The dot operator performs as much dereferencing as the method call needs, avoiding repeated * and & syntax. section 4.3

fn main() {
    let my_name = "Billy".to_string();
    let double_ref = &&my_name;
    println!("{}", double_ref.is_empty());
}

Compare a double reference with a direct method call, then contrast it with the explicit dereferencing form. section 4.3

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains tuple selectors, struct fields, method calls, and automatic dereferencing, but stops short of broader operator rules.
Examples
Demonstrates tuple positions, String emptiness checks through nested references, and struct field access through a borrowed value.
What it assumes
Assumes basic references and tuples while teaching that methods can dereference references automatically.
What you can do after
Apply it via Rust syntax to access tuple elements, read struct fields, and call methods without manually writing every dereference.
How it connects
Connects dotted notation with tuples, structs, methods, references, dereferencing, and destructuring.

Also explained in

Compare how 9 books explain dotted notation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.