Syntax

Rust Define a Struct Syntax

In Rust, define a struct: groups related fields — struct User { name: String, age: u32, }

Quick Answer

Syntax
struct User { name: String, age: u32, }
RustSyntax

Define a Struct

Code example
struct User { name: String, age: u32, }

Groups related fields.

Learn More

How to define a struct in Rust

  1. Open your Rust file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Rust Define a Struct Syntax

Use struct User { name: String, age: u32, }.

Related Syntax References

Frequently asked questions

What is the Rust syntax for define a struct?

Use this pattern: struct User { name: String, age: u32, }

Can I copy this Rust code example?

Yes. Use Copy code and adapt the example to your program.

Is this Rust syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify