-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature renderable filter #48
base: master
Are you sure you want to change the base?
Conversation
Just a general comment, you can use |
If you want to be able to run example files, you also need to edit |
examples/unrenderable.rs
Outdated
fn list_control_characters() -> Vec<char> { | ||
(0x00..=0x1F).map(|i| char::from_u32(i).unwrap()).collect() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to return a Vec
here, you can return impl Iterator<Item = char>
to the same effect:
fn control_chars() -> impl Iterator<Item = char> {
(0x00..=0x1F).map(|i| char::from_u32(i).unwrap())
}
and the code should still compile. The reason is that for looks in rust are actually based on Iterator
s: the thing you are looping over is anything that implements the IntoIterator
trait. The lazy version is better since it saves on an allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The impl ...
return type says "I am returning a concrete type, but I am just not telling you exactly what it is"; it's not actually a dynamic object. The compiler will replace your impl ...
block with the actual type of the thing that you return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better, you can directly construct a Range<char>
:
const ASCII_CONTROL: Range<char> = '\x00'..='\x1F';
and just use that instead (since Range<char>
implements IntoIterator<Item = char>
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right so the idea being that we are only storing one char in memory at a time OK makes sense. Will make this change thanks!
Interestingly, I am able to run the example without this. But will add it nonetheless |
Interesting! In my setup I can't even get syntax highlighting without including it as an example explicitly because rust analyzer complains that it isn't included in the project. |
Work in progress PR for improving control character handling in the rendered output.
Implements:
#44