pub struct Index(/* private fields */);
Expand description
The index of an encoding in Ruby’s internal encodings table.
This is the type Ruby uses to label encoding capable types, so is used with operations that require reading or setting that label.
See Ruby
for methods to get an encoding::Index
.
Implementations§
source§impl Index
impl Index
sourcepub fn ascii8bit() -> Self
pub fn ascii8bit() -> Self
Returns the index for ASCII-8BIT a.k.a. binary.
§Panics
Panics if called from a non-Ruby thread. See
Ruby::ascii8bit_encindex
for the non-panicking version.
sourcepub fn utf8() -> Self
pub fn utf8() -> Self
Returns the index for UTF-8.
§Panics
Panics if called from a non-Ruby thread. See Ruby::utf8_encindex
for the non-panicking version.
sourcepub fn usascii() -> Self
pub fn usascii() -> Self
Returns the index for US-ASCII.
§Panics
Panics if called from a non-Ruby thread. See Ruby::usascii_encindex
for the non-panicking version.
sourcepub fn locale() -> Self
pub fn locale() -> Self
Returns the index for the process’ current locale encoding.
This is dynamic. If you change the process’ locale that should also change the return value of this function.
§Panics
Panics if called from a non-Ruby thread. See Ruby::locale_encindex
for the non-panicking version.
sourcepub fn filesystem() -> Self
pub fn filesystem() -> Self
Returns the index for filesystem encoding.
This is the encoding that Ruby expects data from the OS’ file system to be encoded as, such as directory names.
§Panics
Panics if called from a non-Ruby thread. See
Ruby::filesystem_encindex
for the non-panicking version.
sourcepub fn find(name: &str) -> Result<Self, Error>
pub fn find(name: &str) -> Result<Self, Error>
Returns the index for the encoding with the name or alias name
.
§Panics
Panics if called from a non-Ruby thread. See Ruby::find_encindex
for the non-panicking version.
§Examples
use magnus::encoding;
assert!(encoding::Index::find("UTF-8").is_ok());
assert!(encoding::Index::find("BINARY").is_ok());
assert!(encoding::Index::find("none").is_err());