Sha256: 0b9eda6442a5cd2279cefcdacc1ae327c3c72254d703364f99ed1ff27a6b94b8

Contents?: true

Size: 1008 Bytes

Versions: 14

Compression:

Stored size: 1008 Bytes

Contents

/// Finds or creates a symbol for the given static string. This macro will
/// memoize the ID to avoid repeated calls to libruby. You should prefer this
/// macro over [`rb_intern3`] when the string is known at compile time.
///
/// # Safety
///
/// This macro is safe under two conditions:
///   - Ruby VM is initialized and that thus safe to call into libruby
///   - The first call to this macro will be done inside of a managed Ruby thread (i.e. not a native thread)
///
/// # Example
///
/// ```no_run
/// use rb_sys::{symbol::rb_intern, rb_funcall, rb_utf8_str_new};
///
/// unsafe {
///   let reverse_id = rb_intern!("reverse");
///   let msg = rb_utf8_str_new("nice one".as_ptr() as *mut _, 4);
///   rb_funcall(msg, reverse_id, 0);
/// }
/// ```
#[macro_export]
macro_rules! rb_intern {
    ($s:literal) => {{
        static mut ID: $crate::ID = 0;
        if ID == 0 {
            ID = $crate::rb_intern3($s.as_ptr() as _, $s.len() as _, $crate::rb_utf8_encoding());
        }
        ID
    }};
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rb-sys-0.9.108/src/symbol.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rb-sys-0.9.108/src/symbol.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rb-sys-0.9.103/src/symbol.rs
wasmtime-26.0.0 ./ext/cargo-vendor/rb-sys-0.9.102/src/symbol.rs
wasmtime-25.0.2 ./ext/cargo-vendor/rb-sys-0.9.102/src/symbol.rs
wasmtime-25.0.1 ./ext/cargo-vendor/rb-sys-0.9.102/src/symbol.rs
wasmtime-25.0.0 ./ext/cargo-vendor/rb-sys-0.9.102/src/symbol.rs
wasmtime-24.0.0 ./ext/cargo-vendor/rb-sys-0.9.102/src/symbol.rs
wasmtime-23.0.2 ./ext/cargo-vendor/rb-sys-0.9.100/src/symbol.rs
wasmtime-22.0.0 ./ext/cargo-vendor/rb-sys-0.9.100/src/symbol.rs
wasmtime-21.0.1 ./ext/cargo-vendor/rb-sys-0.9.100/src/symbol.rs
wasmtime-20.0.2 ./ext/cargo-vendor/rb-sys-0.9.97/src/symbol.rs
wasmtime-20.0.0 ./ext/cargo-vendor/rb-sys-0.9.97/src/symbol.rs
wasmtime-18.0.3 ./ext/cargo-vendor/rb-sys-0.9.89/src/symbol.rs