liveBook · Manning

As operator

The as operator is language syntax that associates a value or expression with a specified type through assertion, casting, or conversion, depending on the language.

How 3 Manning books explain it

Learn Rust in a Month of Lunches

The as operator performs explicit primitive-type conversions in Rust.

How it is used
Uses explicit conversion to turn an integer value into a character.
How deep it goes
Works through a rejected cast and two corrections, without detailing conversion rules for every primitive type.
Examples
Shows `100` rejected as an `i32`-to-`char` cast, then converted through `u8`.
What you can do after
Apply it in Rust to correct the illustrated integer-to-character cast.

Read how Learn Rust in a Month of Lunches explains as operator →

Pro Angular 16

A type assertion is TypeScript syntax that tells the compiler to treat an expression as a specified type without changing the runtime value.

How it is used
Resolves TypeScript compiler uncertainty in mixed-type addition and array reduction.
How deep it goes
Demonstrates two assertion sites and their results, while warning that `any` weakens checking; does not examine compiler internals.
Examples
Shows `(param as any) + 100` producing different numeric and string results, and `val as number` in a sum.
What you can do after
Apply it via TypeScript’s `as` keyword where inference falls short, while recognizing that an assertion does not validate runtime values.

Read how Pro Angular 16 explains as operator →

Rust in Action: Systems programming concepts and techniques

The as operator is Rust syntax for explicitly converting a value to another type using a permitted cast.

How it is used
Uses explicit casts to make differently typed numeric values comparable.
How deep it goes
Explains syntax, promotion, narrowing risks, and fallible conversion, while deferring full traits and Result treatment.
Examples
Uses a mixed-type comparison, a narrowing integer cast, and a try_into conversion listing.
What you can do after
Apply explicit numeric casts to resolve compatible comparisons and recognize when fallible conversion is safer.

Read how Rust in Action: Systems programming concepts and techniques explains as operator →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.