Skip to content
ZOLO / TE835 Type · error

invalid cast; use parsing, a predicate, or a domain conversion

`as` performs only compiler-known casts — it does not parse text, compute truthiness, serialize data, or run a conversion implemented by a user type. Use `parse::<T>()`, `to_string()`, `try_into::<T>()`, or an explicit comparison instead.

Why this fires

as only performs compiler-known casts. It does not parse text, compute truthiness, serialize data, or run a conversion implemented by a user type.

let port = "8080" as u16 // error[TE835]

Fix it

Choose the operation that matches the intent:

let port = "8080".parse::<u16>()?
let text = value.to_string()
let user = raw.try_into::<User>()?

Use an explicit comparison instead of casting a value to bool.

See also

  • TE836 — an exact checked cast cannot succeed.
  • TE837 — a numeric cast can lose information.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br