What is character.to_uppercase() in Rust?

Overview

to_uppercase() is a method of the character data type in Rust. It converts a character to its uppercase version. Similar methods are also present in other programming languages.

Syntax

character.to_uppercase()
Syntax for to_uppercase() method in Rust

Parameters

character: This is the character that we want to convert to uppercase.

Return value

The value returned is the uppercase version of character.

Example

fn main(){
// create some characters
let char1 = 'r';
let char2 = 'u';
let char3 = 's';
let char4 = 't';
// convert characters to uppercase
println!("{}", char1.to_uppercase());
println!("{}", char2.to_uppercase());
println!("{}", char3.to_uppercase());
println!("{}", char4.to_uppercase());
}

Explanation

  • Lines 2–6: We create different alphabetical characters.
  • Lines 9–12: With the help of the to_uppercase() method, we convert the characters to uppercase and print them to the console screen.

Free Resources