pub struct Generics { /* private fields */ }Expand description
The generic declarations of a program, the instantiations made from them, and the type parameters bound while a body is being compiled.
Implementations§
Source§impl Generics
impl Generics
Sourcepub const fn template_count(&self) -> usize
pub const fn template_count(&self) -> usize
How many generic declarations are registered.
Sourcepub fn mark_prelude_file(&mut self, file_idx: u16)
pub fn mark_prelude_file(&mut self, file_idx: u16)
Records that file file_idx is a prelude module.
Sourcepub const fn set_prelude_templates(&mut self, range: Range<usize>)
pub const fn set_prelude_templates(&mut self, range: Range<usize>)
Records which templates the prelude registered.
Sourcepub fn bound(&self, name: &str) -> Option<DataType>
pub fn bound(&self, name: &str) -> Option<DataType>
The type this name is currently bound to, if it names a type parameter
of the body being compiled. A parameter nothing named is any.
Sourcepub fn names(&self, name: &str) -> bool
pub fn names(&self, name: &str) -> bool
Whether the call site or an enclosing impl block fixed this type
parameter to a type, as opposed to leaving it standing for any. An
annotation that mentions a parameter nothing named stays un-pinned.
Sourcepub fn params_of(&self, name: &str) -> Option<&[SmolStr]>
pub fn params_of(&self, name: &str) -> Option<&[SmolStr]>
The parameters of the generic declaration name names, for a caller
with no scope to resolve it in: a mangled method name
(Cell<int>#get) carries the type name and no module path. Takes the
declaration registered last when two modules declare the name.
Sourcepub fn set_struct_defaults(
&mut self,
id: u16,
file_idx: u16,
values: Box<[Option<(Expr, Span)>]>,
)
pub fn set_struct_defaults( &mut self, id: u16, file_idx: u16, values: Box<[Option<(Expr, Span)>]>, )
Records the values the fields of struct id were declared with,
replacing whatever an earlier struct of that id left, so an id reused
after a rollback starts clean.
Sourcepub fn struct_default(
&self,
id: u16,
field: usize,
) -> Option<(u16, &Expr, Span)>
pub fn struct_default( &self, id: u16, field: usize, ) -> Option<(u16, &Expr, Span)>
The value field field of struct id was declared with, and the file
it was written in.
Sourcepub fn param_fields(&self, template_idx: usize) -> Vec<Option<SmolStr>>
pub fn param_fields(&self, template_idx: usize) -> Vec<Option<SmolStr>>
For each type parameter of a struct template, the field declared with that parameter as its type. A literal written without type arguments takes each parameter from the value in that field.
Sourcepub fn instantiation_of(&self, t: &DataType) -> Option<(usize, &[DataType])>
pub fn instantiation_of(&self, t: &DataType) -> Option<(usize, &[DataType])>
The declaration an instantiated type came from and the arguments it was made with, for a type that came from one.
Sourcepub fn enum_template_with_variant(&self, variant: &str) -> Option<usize>
pub fn enum_template_with_variant(&self, variant: &str) -> Option<usize>
The generic enum declaration that declares a variant of this name, and the payload types the variant declares.
A generic enum has no registered type until something names one, so a
bare Some(x) is looked up here rather than among the enums already
registered. The last declaration of the name wins, the same as
find_template does for a type name.
Sourcepub fn only_the_prelude_declares(&self, variant: &str) -> bool
pub fn only_the_prelude_declares(&self, variant: &str) -> bool
Whether the only generic enums declaring a variant called variant are
the prelude’s.
Sourcepub fn add_struct_template(
&mut self,
name: SmolStr,
params: TypeParams,
file_idx: u16,
fields: Box<[(SmolStr, TypeExpr, Span)]>,
defaults: Box<[Option<(Expr, Span)>]>,
) -> u32
pub fn add_struct_template( &mut self, name: SmolStr, params: TypeParams, file_idx: u16, fields: Box<[(SmolStr, TypeExpr, Span)]>, defaults: Box<[Option<(Expr, Span)>]>, ) -> u32
Records a generic struct declaration and returns the index the
declaring scope registers it under, which is what a name written
behind a module path resolves to.
Sourcepub fn add_enum_template(
&mut self,
name: SmolStr,
params: TypeParams,
file_idx: u16,
variants: Box<[(SmolStr, Box<[TypeExpr]>, Span)]>,
) -> u32
pub fn add_enum_template( &mut self, name: SmolStr, params: TypeParams, file_idx: u16, variants: Box<[(SmolStr, Box<[TypeExpr]>, Span)]>, ) -> u32
Records a generic enum declaration. Returns its index, as
Generics::add_struct_template does.
Sourcepub fn defines_operator_methods(&self) -> bool
pub fn defines_operator_methods(&self) -> bool
Records the impl blocks a file declared against a generic type,
stamping each with the file it came from.
Whether any impl block the program has read defines an operator,
which makes an operator on that type a call to candela code.
pub fn add_impls(&mut self, impls: Vec<ImplTemplate>, file_idx: u16)
Sourcepub fn path_fn_of_template(&self, template: usize, name: &str) -> Option<String>
pub fn path_fn_of_template(&self, template: usize, name: &str) -> Option<String>
The path a receiverless function name of generic declaration
template is called by, Set<T>::new(), when an impl block on it
declares one.
Sourcepub fn push_bindings(&mut self, frame: Box<[(SmolStr, DataType)]>)
pub fn push_bindings(&mut self, frame: Box<[(SmolStr, DataType)]>)
Binds frame for the body about to be compiled. Every body pushes a
frame, an empty one when it has no type parameters, so the caller’s
parameters do not resolve inside it.
Sourcepub fn push_frame(&mut self, frame: BindingFrame)
pub fn push_frame(&mut self, frame: BindingFrame)
Binds a frame that also carries the parameters nothing named, which a
function specialisation has and an impl block does not.
pub fn pop_bindings(&mut self)
Sourcepub const fn checkpoint(&self) -> GenericsCheckpoint
pub const fn checkpoint(&self) -> GenericsCheckpoint
Snapshots the state a single generic instantiation (or a function
specialization’s own type-parameter frame) can grow or unbalance, so an
aborted compile attempt can undo it with Generics::rollback_to.
instantiations and the structs/enums it names are a cache: an
instantiate call registers the pair before the instantiation’s own
fields are resolved, so a type whose fields name itself resolves to the
type being built instead of recursing. A diagnostic raised while
resolving those fields (or while lowering an impl block against the
instantiation, which pushes its lowered methods the same way a closure
literal pushes an anonymous function) leaves the cache entry pointing at
a struct or enum whose fields were never filled in. bindings and
depth are pushed and incremented, respectively, before that same
resolution and are only popped or decremented after it returns; a
push_bindings without a matching pop_bindings (function
specialization has its own such pair too, see
functions/user_functions.rs) leaks a frame, and an unmatched depth
increment eventually trips the instantiation-depth cap for programs
nowhere near it.
Sourcepub fn rollback_to(&mut self, checkpoint: &GenericsCheckpoint)
pub fn rollback_to(&mut self, checkpoint: &GenericsCheckpoint)
Undoes everything a failed compile attempt did to the instantiation
cache and the binding/depth bookkeeping, back to checkpoint. The
structs and enums an aborted instantiate call registered are not
Generics’ to remove; the caller truncates those (see
Program::rollback_to) using the same pre-attempt lengths.
Trait Implementations§
Auto Trait Implementations§
impl !Send for Generics
impl !Sync for Generics
impl Freeze for Generics
impl RefUnwindSafe for Generics
impl Unpin for Generics
impl UnsafeUnpin for Generics
impl UnwindSafe for Generics
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
§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);