'Syntax highlighting in egui Rust
I'm writing a text editor in Rust using egui. I am trying to implement syntax highlighting,
so I followed the example in the demo. It works there, so I thought it might be useful. But I am getting an error that syntax_highlighting
is not found in the crate root. I have syntect and egui both installed at their latest versions and have them
as dependencies.
let mut theme = crate::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
ui.collapsing("Theme", |ui| {
ui.group(|ui| {
theme.ui(ui);
theme.clone().store_in_memory(ui.ctx());
});
});
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layout_job =
crate::syntax_highlighting::highlight(ui.ctx(), &theme, string, self.language);
layout_job.wrap.max_width = wrap_width;
ui.fonts().layout_job(layout_job)
};
In particular, it is these lines that raise the error that syntax_highlighting
is not found in the crate root. In case it's useful, here is all my code:
https://pastebin.com/mHDhLhSR
I want to implement syntax highlighting to my egui application, but I get the error that syntax_highlighting
is not found in the crate root, which the only example I found used.
Solution 1:[1]
The crate::
means syntax_highlighting
is a member of the egui_demo_lib
crate itself. In this case, you'll find it right here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mrkishi |