[−][src]Crate safecast
safecast
defines traits analogous to From
, Into
, TryFrom
, and TryInto
to
standardize the implementation of casting between Rust types. The can_cast_from
and
can_cast_into
methods borrow the source value, allowing pattern matching without moving.
Example:
let value = serde_json::from_str("1"); if value.matches::<i32>() { println!("It's an integer!"); } else if value.matches::<String>() { let value = String::opt_cast_from(value).unwrap(); println!("no, it's a string: {}", value); }
Traits
CastFrom | Trait for defining a cast operation from some source type |
CastInto | Trait for defining a cast operation to some destination type T.
Analogous to |
Match | Blanket implementation of a convenience method |
TryCastFrom | Trait for defining a cast operation when the source type cannot always be cast to the
destination type. Defines a |
TryCastInto | Trait for defining a cast operation when the destination type cannot always be cast from the
source type. Defines a |