Join my Laravel for REST API's course on Udemy 👀

Fix `character literal may only contain one codepoint` error in Rust

August 25, 2022  ‐ 1 min read

Many programming languages leave it up to you to use single quotes or double quotes for your strings. Sometimes with slight function differences.

In Rust we create a variable of the character type when using single quotes and use double quotes for strings.

Thus, when we define a "string" using single quotes as follows

fn main() {
    let name = 'Koen';

We get the following error:

error: character literal may only contain one codepoint
 --> src/
2 |     let name = 'Koen';

Instead we should use double quotes when defining a string.

fn main() {
    let name = "Koen";