mezzaluna_conversion_methods

Struct ConvMethods

Source
pub struct ConvMethods { /* private fields */ }
Expand description

A table of Ruby conversion methods and their metadata.

This struct provides a lazily initiated lookup table for Ruby object conversion methods and their metadata. See CONVERSION_METHODS for the list of supported conversion methods and ConvMethod for the metadata associated with each method.

Implementations§

Source§

impl ConvMethods

Source

pub const fn new() -> Self

Create a new ConvMethods.

§Examples
use mezzaluna_conversion_methods::ConvMethods;
let methods = ConvMethods::new();
Source

pub fn get(&self) -> Option<&[ConvMethod; 12]>

Get the conversion methods table.

This method returns a reference to the conversion methods table if it has been initialized, or None if it has not been initialized.

§Examples
use mezzaluna_conversion_methods::ConvMethods;

let methods = ConvMethods::new();
assert!(methods.get().is_none());
Source

pub fn get_or_init<'a, S>( &'a self, symbols: &mut SymbolTable<S>, ) -> Result<&'a [ConvMethod; 12], InitError>
where S: BuildHasher,

Get the conversion methods table, initializing it if necessary.

This method returns a reference to the conversion methods table, which is lazily initialized on the first call. This method is idempotent and will return the same reference on subsequent calls.

§Errors

If the table cannot be initialized due to an error interning the symbol, an InitError is returned. Due to limitations of the Rust standard library, this error is never returned and instead causes a panic.

§Panics

This method panics if the symbol table cannot be interned. This should be a rare occurrence, as the symbol table is typically initialized during interpreter setup.

§Examples
use intaglio::bytes::SymbolTable;
use mezzaluna_conversion_methods::{ConvMethods, InitError};

let mut symbols = SymbolTable::new();
let methods = ConvMethods::new();
let table = methods.get_or_init(&mut symbols)?;
assert_eq!(table.len(), 12);
assert!(methods.get().is_some());
Source

pub fn find_method<S>( &self, symbols: &mut SymbolTable<S>, method: &str, ) -> Result<Option<ConvMethod>, InitError>
where S: BuildHasher,

Find the conversion metadata for the given method name.

This method searches the conversion methods table for the specified method name and returns the corresponding conversion metadata if found.

This method will initialize the conversion methods table if it has not been initialized yet.

§Errors

If the conversion methods table cannot be initialized, an InitError is returned. See ConvMethods::get_or_init for more information.

Trait Implementations§

Source§

impl Debug for ConvMethods

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConvMethods

Source§

fn default() -> ConvMethods

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.