pub struct Lowerer<'m, K> { /* private fields */ }Expand description
Lowers syntax trees with one mapping: the configured path, for a budget, a compilation unit other than 0, or host-provided field labels.
§Examples
use hir_lang::UnitId;
use lower_lang::{Arch, Budget, Lowerer, MappingBuilder, Pick};
use syntax_lang::Node;
let mut b = MappingBuilder::new();
b.node(K(0), Arch::Module { name: Pick::Absent, items: Pick::Nodes });
let mapping = b.build()?;
let tree = Node::new(K(0), vec![]);
let mut names = intern_lang::Interner::new();
let out = Lowerer::new(&mapping)
.with_unit(UnitId::new(3))
.with_budget(Budget::default())
.lower(&tree, "", &mut names)
.expect("within budget");
assert_eq!(out.hir.unit(), UnitId::new(3));Implementations§
Source§impl<'m, K> Lowerer<'m, K>
impl<'m, K> Lowerer<'m, K>
Sourcepub fn with_budget(self, budget: Budget) -> Self
pub fn with_budget(self, budget: Budget) -> Self
Sourcepub fn with_labeler(self, labeler: &'m dyn Labeler<K>) -> Self
pub fn with_labeler(self, labeler: &'m dyn Labeler<K>) -> Self
Uses labeler for Pick::Label fields.
§Examples
use lower_lang::{Labeler, Lowerer, MappingBuilder};
use syntax_lang::Node;
struct NoFields;
impl Labeler<K> for NoFields {
fn label(&self, _: &Node<K>, _: usize) -> Option<u16> { None }
}
let mapping = MappingBuilder::<K>::new().build()?;
let _lowerer = Lowerer::new(&mapping).with_labeler(&NoFields);Sourcepub fn lower(
&self,
tree: &Node<K>,
source: &str,
names: &mut Interner,
) -> Result<Lowered, LowerError>
pub fn lower( &self, tree: &Node<K>, source: &str, names: &mut Interner, ) -> Result<Lowered, LowerError>
Lowers tree (parsed from source) into a validated HIR unit, with
names interned in names.
§Errors
Only for exhausted resources: LowerError::NodeBudget,
LowerError::SymbolSpaceExhausted, or LowerError::Hir when
hir-lang’s arenas overflow. Problems in the code are never errors:
they are in Lowered::problems.
§Examples
See Lowerer.
Auto Trait Implementations§
impl<'m, K> !RefUnwindSafe for Lowerer<'m, K>
impl<'m, K> !Send for Lowerer<'m, K>
impl<'m, K> !Sync for Lowerer<'m, K>
impl<'m, K> !UnwindSafe for Lowerer<'m, K>
impl<'m, K> Freeze for Lowerer<'m, K>
impl<'m, K> Unpin for Lowerer<'m, K>
impl<'m, K> UnsafeUnpin for Lowerer<'m, K>
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
Mutably borrows from an owned value. Read more