Struct rutie::Encoding [−][src]
pub struct Encoding { /* fields omitted */ }
Implementations
Creates a UTF-8 instance of Encoding
.
Examples
use rutie::{Encoding, VM};
Encoding::utf8();
Ruby:
Encoding::UTF_8
Creates a US-ASCII instance of Encoding
.
Examples
use rutie::{Encoding, VM};
Encoding::us_ascii();
Ruby:
Encoding::US_ASCII
Creates a new instance of Encoding
from the default external encoding.
Examples
use rutie::{Encoding, VM};
Encoding::default_external();
Ruby:
Encoding.default_external
Creates an instance of Ok(Encoding)
from the default internal encoding
if there is one, otherwise it returns Err(NilClass)
.
Examples
use rutie::{Encoding, VM};
Encoding::default_internal();
Ruby:
Encoding.default_internal
Returns encoding name.
Examples
use rutie::{RString, Encoding, VM};
let enc = Encoding::utf8();
assert_eq!(enc.name(), "UTF-8")
Ruby:
enc = Encoding::UTF_8
enc.name == "UTF-8"
Find an Ok(Encoding)
for given string name or return an Err(AnyException)
.
Examples
use rutie::{VM, Encoding};
let encoding = Encoding::find("UTF-8");
match encoding {
Ok(enc) => assert_eq!(enc.name(), "UTF-8"),
Err(_) => unreachable!()
}
Ruby:
encoding = Encoding.find("UTF-8")
encoding.name == "UTF-8"
The following is an example where a Ruby exception object of ArgumentError
is returned.
use rutie::{VM, Encoding, Exception};
let encoding = Encoding::find("UTF8");
match encoding {
Ok(_) => unreachable!(),
Err(e) => assert_eq!(e.message(), "unknown encoding name - UTF8")
}
Returns an instance of Ok(Encoding)
if the objects are
compatible encodings, otherwise it returns Err(NilClass)
.
Examples
use rutie::{Encoding, VM, RString, NilClass};
let utf8 = RString::new_utf8("asdf");
let us_ascii= RString::new_usascii_unchecked("qwerty");
let result = Encoding::is_compatible(&utf8, &us_ascii);
assert!(result.is_ok());
let result = Encoding::is_compatible(&utf8, &NilClass::new());
assert!(result.is_err());
Trait Implementations
Returns a singleton class of current object. Read more
Gets an immutable reference to the Rust structure which is wrapped into a Ruby object. Read more
Gets a mutable reference to the Rust structure which is wrapped into a Ruby object.
Defines an instance method for the given class or object. Read more
Defines a private instance method for the given class or object. Read more
Defines a class method for given class or singleton method for object. Read more
An alias for define_method
(similar to Ruby syntax def some_method
).
An alias for define_private_method
(similar to Ruby syntax private def some_method
).
An alias for define_singleton_method
(similar to Ruby def self.some_method
).
Calls a given method on an object similarly to Ruby Object#send
method Read more
Checks whether the object responds to given method Read more
fn protect_send(
&self,
method: &str,
arguments: &[AnyObject]
) -> Result<AnyObject, AnyException>
fn protect_send(
&self,
method: &str,
arguments: &[AnyObject]
) -> Result<AnyObject, AnyException>
protect_send
returns Result<AnyObject, AnyObject> Read more
fn protect_public_send(
&self,
method: &str,
arguments: &[AnyObject]
) -> Result<AnyObject, AnyException>
fn protect_public_send(
&self,
method: &str,
arguments: &[AnyObject]
) -> Result<AnyObject, AnyException>
protect_public_send
returns Result<AnyObject, AnyObject> Read more
Converts struct to AnyObject
Read more
Gets an instance variable of object Read more
Sets an instance variable for object Read more
Unsafely casts current object to the specified Ruby type Read more
Safely casts current object to the specified Ruby type Read more