Trait magnus::symbol::IntoSymbol

source ·
pub trait IntoSymbol: Sized {
    // Required method
    fn into_symbol_with(self, handle: &Ruby) -> Symbol;

    // Provided methods
    fn into_symbol(self) -> Symbol { ... }
    unsafe fn into_symbol_unchecked(self) -> Symbol { ... }
}
Expand description

Conversions from Rust types into Symbol.

Required Methods§

source

fn into_symbol_with(self, handle: &Ruby) -> Symbol

Convert self into Symbol.

§Examples
use magnus::{rb_assert, symbol::IntoSymbol, Ruby};

let ruby = Ruby::get().unwrap();
let sym = "example".into_symbol_with(&ruby);
rb_assert!(ruby, "sym == :example", sym);

Provided Methods§

source

fn into_symbol(self) -> Symbol

Convert self into Symbol.

§Panics

Panics if called from a non-Ruby thread. See IntoSymbol::into_symbol_with for the non-panicking version.

§Examples
use magnus::{rb_assert, symbol::IntoSymbol};

let sym = "example".into_symbol();
rb_assert!("sym == :example", sym);
source

unsafe fn into_symbol_unchecked(self) -> Symbol

Convert self into Symbol.

§Safety

This method should only be called from a Ruby thread.

§Examples
use magnus::{rb_assert, symbol::IntoSymbol};

// only safe when called from a Ruby thread
let sym = unsafe { "example".into_symbol_unchecked() };
rb_assert!("sym == :example", sym);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl IntoSymbol for &str

source§

fn into_symbol_with(self, handle: &Ruby) -> Symbol

source§

impl IntoSymbol for String

source§

fn into_symbol_with(self, handle: &Ruby) -> Symbol

Implementors§