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
impl ConvMethods
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new ConvMethods
.
§Examples
use mezzaluna_conversion_methods::ConvMethods;
let methods = ConvMethods::new();
Sourcepub fn get(&self) -> Option<&[ConvMethod; 12]>
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());
Sourcepub fn get_or_init<'a, S>(
&'a self,
symbols: &mut SymbolTable<S>,
) -> Result<&'a [ConvMethod; 12], InitError>where
S: BuildHasher,
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());
Sourcepub fn find_method<S>(
&self,
symbols: &mut SymbolTable<S>,
method: &str,
) -> Result<Option<ConvMethod>, InitError>where
S: BuildHasher,
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.