Syntax

Rust Create a String Syntax

In Rust, create a string: creates an owned string — let s = String::from("hi");

Quick Answer

Syntax
let s = String::from("hi");
RustSyntax

Create a String

Code example
let s = String::from("hi");

Creates an owned string.

Learn More

How to create a string in Rust

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

Rust Create a String Syntax

Use let s = String::from("hi");.

Related Syntax References

Frequently asked questions

What is the Rust syntax for create a string?

Use this pattern: let s = String::from("hi");

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