pub struct Data { /* private fields */ }Expand description
A NaN-boxed word, plus the word an int needs.
§Layout:
- first 13 bits are NaN
- remaining 51 bits: 3 bits for type (4 for the MAP type) & 48 bits of actual payload (47 for the MAP type)
§Data type:
- BOOL = 001
- STRING_SMALL = 010
- STRING_LARGE = 011
- ARRAY = 100
- NULL = 101
- INT = 110
- STRUCT = 111
- MAP = 1111
§Functions
A function value is an ARRAY with the top payload bit set, which is what tells it from the list it is built as.
§Strings
Strings are inlined if they’re 6 bytes long or less.
If they’re longer, they’re stored in string_pool.
Implementations§
Source§impl Data
impl Data
Sourcepub const fn into_words(self) -> (u64, i64)
pub const fn into_words(self) -> (u64, i64)
The pair of words a .cdlb records a value as. The artifact keeps the
box and the integer rather than a type tag, so a value comes back
without being inspected.
Sourcepub unsafe fn load(src: *const Self) -> Self
pub unsafe fn load(src: *const Self) -> Self
Reads the value at src as two separate words.
Most instructions write a result a word at a time: the tag and the integer are stored apart. A copy that then read the value back as one 16-byte load would have to wait for both stores to reach the cache, because the processor forwards a pending store only to a load that fits inside it. Reading the words apart lets each one forward. The reads are volatile so the compiler cannot fuse them back into one.
§Safety
src must point to a live value.
Sourcepub const fn is_false(self) -> bool
pub const fn is_false(self) -> bool
Whether this is false. A bool keeps its whole value in the box, so
the box alone answers, and the integer word is never read.
Sourcepub const fn from_words(boxed: u64, int: i64) -> Self
pub const fn from_words(boxed: u64, int: i64) -> Self
Rebuilds a value from the words Data::into_words handed out.
pub const fn tag(self) -> u64
pub const fn is_null(self) -> bool
pub const fn bool(b: bool) -> Self
pub fn as_bool(self) -> bool
pub const fn is_bool(self) -> bool
pub const fn float(n: f64) -> Self
pub const fn as_float(self) -> f64
pub const fn is_float(self) -> bool
Sourcepub const fn int(n: i64) -> Self
pub const fn int(n: i64) -> Self
Convert the given integer to a tagged integer. The box carries the tag and the second word carries all 64 bits.
pub const fn as_int(self) -> i64
pub const fn is_int(self) -> bool
pub const fn array(id: u32) -> Self
pub const fn as_array(self) -> usize
pub const fn is_array(self) -> bool
Sourcepub const fn function(id: u32) -> Self
pub const fn function(id: u32) -> Self
A function value over the pool entry id: the array a call reads the
body location and the captured cells out of, marked as the function it
is.
Sourcepub const fn is_function(self) -> bool
pub const fn is_function(self) -> bool
Whether this value is a function. A function value answers
Self::is_array too, since everything that holds, walks and frees an
array holds, walks and frees this one.
Sourcepub fn small_str(s: &str) -> Self
pub fn small_str(s: &str) -> Self
This will create a new inlined string.
In debug it’ll panic (just in case).
The caller guarantees that s is never longer than 6 bytes.
pub const fn large_str_id(id: u64) -> Self
Sourcepub fn as_map_key(self, string_pool: &StringPool) -> Self
pub fn as_map_key(self, string_pool: &StringPool) -> Self
This value as a map stores it for a key. A string in the pool takes a
hash of its text into its second word, which only an int otherwise
uses, arranged so the value hashes as the text does rather than as the
slot: two strings with the same text in different slots then land in
the same bucket, where the map compares them by text. See
crate::vm::KeyByText.
Sourcepub fn p_str(s: &str, string_pool: &mut StringPool) -> Self
pub fn p_str(s: &str, string_pool: &mut StringPool) -> Self
Same as str(), except this never runs the GC because this function is called by the compiler
Sourcepub fn interned(s: &str, string_pool: &mut StringPool) -> Option<Self>
pub fn interned(s: &str, string_pool: &mut StringPool) -> Option<Self>
s as a value without allocating: inline if it is six bytes or
shorter, else the pool slot already holding it, if one does.
Sourcepub fn string<S: PoolString>(
s: S,
array_pool: &mut ObjectPool,
map_pool: &mut MapPool,
string_pool: &mut StringPool,
registers: &RegisterFile,
recursion_stack: &RegisterFile,
gc: &mut GcState,
) -> Self
pub fn string<S: PoolString>( s: S, array_pool: &mut ObjectPool, map_pool: &mut MapPool, string_pool: &mut StringPool, registers: &RegisterFile, recursion_stack: &RegisterFile, gc: &mut GcState, ) -> Self
Allocates a string, storing it directly inside the value if it is six
bytes or shorter and in the string pool otherwise. A pooled string can
start a collection, so every value the program still holds has to be
reachable from registers or recursion_stack.
pub fn as_str(&self, string_pool: &StringPool) -> &str
Sourcepub fn str_is_ascii(&self, string_pool: &StringPool) -> bool
pub fn str_is_ascii(&self, string_pool: &StringPool) -> bool
True when every character of this string takes a single byte. A character position on such a string is a byte position, which is the route indexing and slicing take when they can.
Sourcepub fn str_char_len(&self, string_pool: &StringPool) -> usize
pub fn str_char_len(&self, string_pool: &StringPool) -> usize
How many characters this string has. Positions on a string count
characters, so this is what len answers and what an index or a slice
bound is checked against.
Sourcepub fn str_byte_offset(
&self,
char_idx: usize,
string_pool: &StringPool,
) -> usize
pub fn str_byte_offset( &self, char_idx: usize, string_pool: &StringPool, ) -> usize
The byte offset character char_idx starts at. The string has at least
char_idx characters; at exactly that many the answer is its byte
length, which is what a slice bound on the end of the string asks for.
pub const fn is_string(self) -> bool
pub const fn is_large_str(self) -> bool
pub const fn get_str_pool_id(self) -> usize
pub const fn struct_instance(type_id: u16, id: u32) -> Self
pub const fn as_struct(self) -> usize
pub const fn enum_instance(type_id: u16, id: u32) -> Self
pub const fn as_enum(self) -> usize
pub const fn enum_type_id(self) -> u16
pub const fn is_enum(self) -> bool
pub const fn struct_type_id(self) -> u16
pub const fn is_struct(self) -> bool
pub const fn map(id: u32) -> Self
pub const fn as_map(self) -> usize
pub const fn is_map(self) -> bool
Sourcepub const fn type_name(self) -> &'static str
pub const fn type_name(self) -> &'static str
A short runtime type name, used in downcast error messages. Reads only the box tag, so it needs no pools.
pub fn format( self, obj_pool: &ObjectPool, string_pool: &StringPool, map_pool: &MapPool, structs: &[Struct], enums: &[EnumType], show_str: bool, ) -> SmolStr
Trait Implementations§
impl Copy for Data
impl Eq for Data
Source§impl Equivalent<Data> for KeyByText<'_>
impl Equivalent<Data> for KeyByText<'_>
Source§fn equivalent(&self, stored: &Data) -> bool
fn equivalent(&self, stored: &Data) -> bool
key and return true if they are equal.Source§impl Hash for Data
impl Hash for Data
Source§fn hash<H: Hasher>(&self, state: &mut H)
fn hash<H: Hasher>(&self, state: &mut H)
Both words in one, so an int hashes by its value and every other type
hashes by its box exactly as it did when the box was the whole value,
except a pooled string stored as a map key, which hashes by its text
(see Data::as_map_key). DataHash keeps only the last word written,
so writing them apart would collapse every non-int onto the same
hash.
impl StructuralPartialEq for Data
Auto Trait Implementations§
impl Freeze for Data
impl RefUnwindSafe for Data
impl Send for Data
impl Sync for Data
impl Unpin for Data
impl UnsafeUnpin for Data
impl UnwindSafe for Data
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);