Ruby: include/ruby/internal/core/rstruct.h File Reference

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

Macros | Functions
rstruct.h File Reference

Routines to manipulate struct RStruct. More...

`#include "ruby/internal/attr/artificial.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/value.h"`
`#include "ruby/internal/value_type.h"`
`#include "ruby/internal/arithmetic/long.h"`
`#include "ruby/internal/arithmetic/int.h"`
`#include "ruby/backward.h"`

Go to the source code of this file.

## Macros
#define | RSTRUCT_PTR(st)

## Functions
VALUE | rb_struct_size (VALUE st)
| Returns the number of struct members.
VALUE | rb_struct_aref (VALUE st, VALUE k)
| Resembles `Struct#[]`.
VALUE | rb_struct_aset (VALUE st, VALUE k, VALUE v)
| Resembles `Struct#[]=`.
static long | RSTRUCT_LEN (VALUE st)
| Returns the number of struct members.
static VALUE | RSTRUCT_SET (VALUE st, int k, VALUE v)
| Resembles `Struct#[]=`.
static VALUE | RSTRUCT_GET (VALUE st, int k)
| Resembles `Struct#[]`.

## Detailed Description

Routines to manipulate struct RStruct.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.
  The struct RStruct itself is opaque.

Definition in file rstruct.h.

## Macro Definition Documentation

## ◆ RSTRUCT_PTR

#define RSTRUCT_PTR | ( |  | st | ) |

Value:
rb_struct_ptr(st)

Deprecated
  This macro once was a thing in the old days, but makes no sense any longer today. Exists here for backwards compatibility only. You can safely forget about it.

Definition at line 45 of file rstruct.h.

## Function Documentation

## ◆ rb_struct_aref()

VALUE rb_struct_aref | ( | VALUE | st,
|  | VALUE | k )

Resembles `Struct#[]`.

Parameters

  [in] | st | An instance of RStruct.
  [in] | k | Index a.k.a. key of the struct.

Exceptions

  rb_eTypeError | `k` is neither Numeric, Symbol, nor String.
  rb_eIndexError | Numerical index out of range.
  rb_eNameError | No such key.

Returns
  The member stored at `k` in `st`.

Precondition
  `st` must be of RUBY_T_STRUCT.

Definition at line 1259 of file struct.c.

Referenced by rb_struct_aref(), and RSTRUCT_GET().

## ◆ rb_struct_aset()

VALUE rb_struct_aset | ( | VALUE | st,
|  | VALUE | k,
|  | VALUE | v )

Resembles `Struct#[]=`.

Parameters

  [out] | st | An instance of RStruct.
  [in] | k | Index a.k.a. key of the struct.
  [in] | v | Value to store.

Exceptions

  rb_eTypeError | `k` is neither Numeric, Symbol, nor String.
  rb_eIndexError | Numerical index out of range.
  rb_eNameError | No such key.

Returns
  Passed `v`.

Precondition
  `st` must be of RUBY_T_STRUCT.

Postcondition
  `v` is stored at `k` in `st`.

Definition at line 1297 of file struct.c.

Referenced by rb_struct_aset(), and RSTRUCT_SET().

## ◆ rb_struct_size()

VALUE rb_struct_size | ( | VALUE | st | ) |

Returns the number of struct members.

Parameters

  [in] | st | An instance of RStruct.

Returns
  The number of members of `st`.

Precondition
  `st` must be of RUBY_T_STRUCT.

Definition at line 1550 of file struct.c.

Referenced by rb_struct_size(), and RSTRUCT_LEN().

## ◆ RSTRUCT_GET()

static VALUE RSTRUCT_GET | ( | VALUE | st,
|  | int | k )
| inlinestatic

Resembles `Struct#[]`.

Parameters

  [in] | st | An instance of RStruct.
  [in] | k | Index a.k.a. key of the struct.

Exceptions

  rb_eTypeError | `k` is neither Numeric, Symbol, nor String.
  rb_eIndexError | Numerical index out of range.
  rb_eNameError | No such key.

Returns
  The member stored at `k` in `st`.

Precondition
  `st` must be of RUBY_T_STRUCT.

Definition at line 114 of file rstruct.h.

## ◆ RSTRUCT_LEN()

static long RSTRUCT_LEN | ( | VALUE | st | ) |
| inlinestatic

Returns the number of struct members.

Parameters

  [in] | st | An instance of RStruct.

Returns
  The number of members of `st`.

Precondition
  `st` must be of RUBY_T_STRUCT.

Definition at line 94 of file rstruct.h.

## ◆ RSTRUCT_SET()

static VALUE RSTRUCT_SET | ( | VALUE | st,
|  | int | k,
|  | VALUE | v )
| inlinestatic

Resembles `Struct#[]=`.

Parameters

  [out] | st | An instance of RStruct.
  [in] | k | Index a.k.a. key of the struct.
  [in] | v | Value to store.

Exceptions

  rb_eTypeError | `k` is neither Numeric, Symbol, nor String.
  rb_eIndexError | Numerical index out of range.
  rb_eNameError | No such key.

Returns
  Passed `v`.

Precondition
  `st` must be of RUBY_T_STRUCT.

Postcondition
  `v` is stored at `k` in `st`.

Definition at line 104 of file rstruct.h.