You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use syntect::easy::HighlightLines;use syntect::highlighting::{Style,ThemeSet};use syntect::parsing::SyntaxSet;use syntect::util::{as_24_bit_terminal_escaped, split_at,LinesWithEndings};fnmain(){let ps = SyntaxSet::load_defaults_newlines();let ts = ThemeSet::load_defaults();let syntax = ps.find_syntax_by_extension("rs").unwrap();letmut h = HighlightLines::new(syntax,&ts.themes["base16-ocean.dark"]);let s = "日本の首都は東京です";for line inLinesWithEndings::from(s){let ranges:Vec<(Style,&str)> = h.highlight_line(line,&ps).unwrap();//thread 'main' panicked at 'byte index 4 is not a char boundary; it is inside '本' (bytes 3..6) of `日本の首都は東京です`', library/core/src/str/mod.rs:127:5let ranges = split_at(&ranges,4);let escaped = as_24_bit_terminal_escaped(&ranges.0,false);print!("{}", escaped);println!();}}
I think it would be better to return Result<(Vec..., Vec...), Error> instead of (Vec... , Vec...) to avoid this type of panic.
The text was updated successfully, but these errors were encountered:
Created 2 PR to fix this issue: One is to fix this function to return Result, another to return the same type as before, just decreases the index to avoid panic. Which is preferred I cannot say, so please check.
Sorry if duplicated.
To reproduce panic, run the following code:
I think it would be better to return
Result<(Vec..., Vec...), Error>
instead of(Vec... , Vec...)
to avoid this type of panic.The text was updated successfully, but these errors were encountered: