Difference between len() vs chars().count() in Rust

Newbie might misunderstand between them.

Photo by Kevin Lang on Unsplash

If you are coming from different languages like Python, you might guess that len() return the length of variable, if it is String, means the number of characters in it, but indeed it is not.

Instead String.len() return the bytes of that String.

--

--

--

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Java Interview — Crash Course [Part 2]

Get rid of full disk in Ubuntu

Introduction to Git

Security Best Practices for Backend Developers

C++ Interview Questions- Common But Essential C++ Questions!

Linux: What does ‘1>/dev/null 2>&1’ actually mean

Create Gitlab project for the app’s code repository

How the Penguin Sausage is Made

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Le

Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

More from Medium

Lambda Calculus: an Elm CLI

Let’s Build a Salesforce Commerce Cloud Products Search Component with OCAPI, Rust, and Yew — Part…

Clash of the compiled: Golang vs Rust

Why Rust excites me

Me, coding in 2004. I was able to keep only a quarter of my hair.