Skip to main content

runestick/
lib.rs

1//! <div align="center">
2//!     <img alt="Rune Logo" src="https://raw.githubusercontent.com/rune-rs/rune/main/assets/icon.png" />
3//! </div>
4//!
5//! <br>
6//!
7//! <div align="center">
8//! <a href="https://rune-rs.github.io">
9//!     <b>Visit the site 🌐</b>
10//! </a>
11//! -
12//! <a href="https://rune-rs.github.io/book/">
13//!     <b>Read the book 📖</b>
14//! </a>
15//! </div>
16//!
17//! <br>
18//!
19//! <div align="center">
20//! <a href="https://github.com/rune-rs/rune/actions">
21//!     <img alt="Build Status" src="https://github.com/rune-rs/rune/workflows/Build/badge.svg">
22//! </a>
23//!
24//! <a href="https://github.com/rune-rs/rune/actions">
25//!     <img alt="Site Status" src="https://github.com/rune-rs/rune/workflows/Site/badge.svg">
26//! </a>
27//!
28//! <a href="https://crates.io/crates/rune">
29//!     <img alt="crates.io" src="https://img.shields.io/crates/v/rune.svg">
30//! </a>
31//!
32//! <a href="https://docs.rs/rune">
33//!     <img alt="docs.rs" src="https://docs.rs/rune/badge.svg">
34//! </a>
35//!
36//! <a href="https://discord.gg/v5AeNkT">
37//!     <img alt="Chat on Discord" src="https://img.shields.io/discord/558644981137670144.svg?logo=discord&style=flat-square">
38//! </a>
39//! </div>
40//!
41//! <br>
42//!
43//! A stack-based virtual machine for the Rust programming language.
44//!
45//! This is the driver for the [Rune Language](https://rune-rs.github.io).
46
47#![deny(missing_docs)]
48#![allow(clippy::enum_variant_names, clippy::too_many_arguments)]
49
50mod any;
51mod context;
52mod value;
53mod vm;
54#[macro_use]
55mod macros;
56mod access;
57mod any_obj;
58mod args;
59mod awaited;
60pub mod budget;
61mod bytes;
62mod call;
63mod compile_meta;
64mod const_value;
65pub mod debug;
66mod env;
67pub mod format;
68mod from_value;
69mod function;
70mod future;
71mod generator;
72mod generator_state;
73mod guarded_args;
74mod hash;
75mod id;
76mod inst;
77mod internal;
78mod item;
79mod iterator;
80mod key;
81mod label;
82mod location;
83pub mod module;
84pub mod modules;
85mod named;
86mod names;
87mod object;
88mod panic;
89mod protocol;
90mod protocol_caller;
91mod range;
92mod raw_str;
93mod runtime_context;
94mod select;
95mod shared;
96mod source;
97mod span;
98mod spanned_error;
99mod stack;
100mod static_string;
101mod static_type;
102mod stream;
103mod to_value;
104mod tuple;
105mod type_info;
106mod type_of;
107mod unit;
108mod variant;
109mod vec;
110mod vec_tuple;
111mod visibility;
112mod vm_call;
113mod vm_error;
114mod vm_execution;
115mod vm_halt;
116
117/// Construct a span that can be used during pattern matching.
118///
119/// # Examples
120///
121/// ```rust
122/// use runestick::{Span, span};
123///
124/// let s = Span::new(0, 10);
125///
126/// assert!(match s {
127///     span!(0, 10) => true,
128///     _ => false,
129/// });
130/// ```
131#[macro_export]
132macro_rules! span {
133    ($start:expr, $end:expr) => {
134        $crate::Span {
135            start: $crate::ByteIndex($start),
136            end: $crate::ByteIndex($end),
137        }
138    };
139}
140
141/// The identifier of a source file.
142pub type SourceId = usize;
143
144/// Exported result type for convenience.
145pub type Result<T, E = anyhow::Error> = std::result::Result<T, E>;
146
147/// Exported boxed error type for convenience.
148pub type Error = anyhow::Error;
149
150pub use self::any_obj::{AnyObj, AnyObjError, AnyObjVtable};
151pub use self::args::Args;
152pub use self::compile_meta::{
153    CompileItem, CompileMeta, CompileMetaCapture, CompileMetaEmpty, CompileMetaKind,
154    CompileMetaStruct, CompileMetaTuple, CompileMod, CompileSource,
155};
156pub use self::const_value::ConstValue;
157pub use self::format::{Format, FormatSpec};
158pub use self::from_value::{FromValue, UnsafeFromValue};
159pub use self::generator::Generator;
160pub use self::generator_state::GeneratorState;
161pub use self::guarded_args::GuardedArgs;
162pub use self::id::Id;
163pub use self::iterator::Iterator;
164pub use self::key::Key;
165pub use self::label::{DebugLabel, Label};
166pub use self::location::Location;
167pub use self::module::{InstFnNameHash, InstallWith, Module};
168pub use self::named::Named;
169pub use self::raw_str::RawStr;
170pub use self::runtime_context::RuntimeContext;
171pub use self::select::Select;
172pub use self::source::Source;
173pub use self::span::{ByteIndex, IntoByteIndex, Span};
174pub use self::spanned_error::{SpannedError, WithSpan};
175pub use self::static_string::StaticString;
176pub use self::static_type::{
177    StaticType, BOOL_TYPE, BYTES_TYPE, BYTE_TYPE, CHAR_TYPE, FLOAT_TYPE, FORMAT_TYPE,
178    FUNCTION_TYPE, FUTURE_TYPE, GENERATOR_STATE_TYPE, GENERATOR_TYPE, INTEGER_TYPE, ITERATOR_TYPE,
179    OBJECT_TYPE, OPTION_TYPE, RANGE_TYPE, RESULT_TYPE, STREAM_TYPE, STRING_TYPE, TUPLE_TYPE, TYPE,
180    UNIT_TYPE, VEC_TYPE,
181};
182pub use self::stream::Stream;
183pub use self::to_value::{ToValue, UnsafeToValue};
184pub use self::tuple::Tuple;
185pub use self::type_info::TypeInfo;
186pub use self::variant::{Variant, VariantData};
187pub use self::vec::Vec;
188pub use crate::access::{
189    AccessError, BorrowMut, BorrowRef, NotAccessibleMut, NotAccessibleRef, RawAccessGuard,
190};
191pub use crate::any::Any;
192pub use crate::awaited::Awaited;
193pub use crate::bytes::Bytes;
194pub use crate::call::Call;
195pub use crate::context::{Context, ContextError, ContextSignature, ContextTypeInfo};
196pub use crate::debug::{DebugInfo, DebugInst};
197pub use crate::function::{Function, SyncFunction};
198pub use crate::future::Future;
199pub use crate::hash::{Hash, IntoTypeHash};
200pub use crate::inst::{
201    Inst, InstAddress, InstAssignOp, InstOp, InstRangeLimits, InstTarget, InstValue, InstVariant,
202    PanicReason, TypeCheck,
203};
204pub use crate::item::{Component, ComponentRef, IntoComponent, Item};
205pub use crate::names::Names;
206pub use crate::object::Object;
207pub use crate::panic::Panic;
208pub use crate::protocol::Protocol;
209pub use crate::range::{Range, RangeLimits};
210pub use crate::shared::{Mut, RawMut, RawRef, Ref, Shared, SharedPointerGuard};
211pub use crate::stack::{Stack, StackError};
212pub use crate::type_of::TypeOf;
213pub use crate::unit::{Unit, UnitFn};
214pub use crate::value::{Rtti, Struct, TupleStruct, UnitStruct, Value, VariantRtti};
215pub use crate::vec_tuple::VecTuple;
216pub use crate::visibility::Visibility;
217pub use crate::vm::{CallFrame, Vm};
218pub use crate::vm_call::VmCall;
219pub use crate::vm_error::{VmError, VmErrorKind, VmIntegerRepr};
220pub use crate::vm_execution::{VmExecution, VmSendExecution};
221pub use crate::vm_halt::{VmHalt, VmHaltInfo};
222pub(crate) use runestick_macros::__internal_impl_any;
223pub use runestick_macros::{Any, FromValue};
224
225mod collections {
226    pub use hashbrown::{hash_map, HashMap};
227    pub use hashbrown::{hash_set, HashSet};
228    pub use std::collections::{btree_map, BTreeMap};
229}