Struct magnus::encoding::Index

source ·
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

source

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.

source

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.

source

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.

source

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.

source

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.

source

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());

Trait Implementations§

source§

impl Clone for Index

source§

fn clone(&self) -> Index

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl From<Encoding> for Index

source§

fn from(val: Encoding) -> Self

Converts to this type from the input type.
source§

impl From<Index> for RbEncoding

source§

fn from(val: Index) -> Self

Converts to this type from the input type.
source§

impl From<RbEncoding> for Index

source§

fn from(val: RbEncoding) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Index

source§

fn eq(&self, other: &Index) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryConvert for Index

source§

fn try_convert(val: Value) -> Result<Self, Error>

Convert val into Self.
source§

impl Copy for Index

source§

impl Eq for Index

source§

impl StructuralPartialEq for Index

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnwindSafe for Index

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.