[−][src]Trait rutie::TryConvert
Implicit conversion or nil
.
This is meant for “implicit conversions” much like Ruby's:
Array.try_convert
Hash.try_convert
String.try_convert
Regexp.try_convert
IO.try_convert
This is NOT Rust object to Rust object casting for Ruby objects like try_convert_to<T>
is.
Associated Types
type Nil
The type returned in the event of a conversion error.
Required methods
fn try_convert(value: T) -> Result<Self, Self::Nil>
Performs the conversion.
Implementors
impl TryConvert<AnyObject> for AnyException
[src]
impl TryConvert<AnyObject> for RString
[src]
Implicit or nil
conversion
Examples
use rutie::{RString, Fixnum, VM, TryConvert, NilClass, Object}; let four = Fixnum::new(4); let result = RString::try_convert(four.to_any_object()); assert_eq!(result, Err(NilClass::new())); let five = RString::new_utf8("5"); let result2 = RString::try_convert(five.to_any_object()); if let Ok(r) = result2 { assert_eq!(r.to_str(), "5") } else { unreachable!() }
Ruby:
four = 4
result = String.try_convert(four)
result == nil
five = "5"
result = String.try_convert(five)
result == "5"