Symbol

Struct Symbol 

Source
pub struct Symbol(/* private fields */);
Expand description

Ruby Symbol (interned string, immediate value).

Symbols are Ruby’s interned strings - immutable strings that are stored once and reused. They’re commonly used for hash keys and method names.

Symbol is an immediate value and does not require GC protection or pinning.

§Example

use solidus::types::Symbol;

let sym = Symbol::new("hello");
assert_eq!(sym.name().unwrap(), "hello");

Implementations§

Source§

impl Symbol

Source

pub fn new(name: &str) -> Self

Create or get an existing symbol from a string.

Symbols are interned, so calling this with the same string multiple times will return the same Symbol.

§Example
use solidus::types::Symbol;

let sym1 = Symbol::new("foo");
let sym2 = Symbol::new("foo");
assert_eq!(sym1.as_value(), sym2.as_value());
Source

pub fn name(self) -> Result<String, Error>

Get the symbol’s name as a String.

§Errors

Returns an error if the symbol name contains invalid UTF-8.

Trait Implementations§

Source§

impl Clone for Symbol

Source§

fn clone(&self) -> Symbol

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Symbol

Source§

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

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

impl IntoValue for Symbol

Source§

fn into_value(self) -> Value

Convert self into a Ruby Value.
Source§

impl ReprValue for Symbol

Source§

fn as_value(self) -> Value

Get this value as a base Value.
Source§

unsafe fn from_value_unchecked(val: Value) -> Self

Create from a Value without type checking. Read more
Source§

fn as_raw(self) -> VALUE

Get the raw Ruby VALUE. Read more
Source§

fn is_nil(self) -> bool

Check if this value is nil.
Source§

fn is_truthy(self) -> bool

Check if this value is truthy (not nil or false).
Source§

impl TryConvert for Symbol

Source§

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

Try to convert a Ruby Value to this type. Read more
Source§

impl Copy for Symbol

Auto Trait Implementations§

§

impl Freeze for Symbol

§

impl RefUnwindSafe for Symbol

§

impl Send for Symbol

§

impl Sync for Symbol

§

impl Unpin for Symbol

§

impl UnwindSafe for Symbol

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.