|
|
Subscribe / Log in / New account

Toward a better list iterator for the kernel

Toward a better list iterator for the kernel

Posted Mar 14, 2022 19:51 UTC (Mon) by jem (subscriber, #24231)
In reply to: Toward a better list iterator for the kernel by alonz
Parent article: Toward a better list iterator for the kernel

The difference between C and Rust is that Rust allows you reuse a variable name in the same block, which is an error i C.

The scope of a Rust variable variable ends either at the end of the block, or when a new variable with the same name is declared. You can use the old variable when computing the initial value of the new variable, i.e. you can initialize a variable with the value of the variable "itself".

This can be used to change a variable from being mutable to immutable when there is no need to change the value after some point in the program. (Technically there are two separate variables with the same name.)


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds