Closed Geobert closed 5 years ago
use hex_view::HexView;
#[derive(Debug, Serialize, Deserialize)]
pub struct Token {
pub session_token: String,
}
impl Deref for Token {
type Target = String;
fn deref(&self) -> &String {
&self.session_token
}
}
impl From<[u8; 32]> for Token {
fn from(s: [u8; 32]) -> Self {
Token {
session_token: format!("{:x}", HexView::from(&s)),
}
}
}
And here we go (=. I'll try to explain my point. The main purpose of syntax highlighting, in my personal opinion, is to make code more readable. Let's look at comparison below:
Which one is more readable? For me it's the first one. Because it emphasises on more meaningful part. Yes, enum is a type, no doubt. But it's also an aggregation for other types, so we can think of it as some kind of namespace, or scope if you like. Maybe it's my fault, and I should call it scope
instead of namespace
. But I realized it only now (=.
For example in C++ we can define class inside class. And in this case OuterClass is in fact namespace for InnerClass, while it's still a type. And constructions like OuterClass::InnerClass
is not very different from std::string
. The same applies to SomeClass::staticFunction()
, here SomeClass is nothing but namespace for staticFunction().
What I'm trying to say, is that maybe editors, you are used to, highlight every occurrence of type as "type". But here, making our own highlighter, we can do something better, provide more readable coloring. Maybe we are not like others, but it doesn't mean we're worse and should copy them.
I totally understand your point here. Now I'm mitigated between semantically correctness and readability. I don't know what the Rust community will prefer ^^'
I think you're right on this one, I'll close the issue then :)
I believe several days with such highlighting and everyone will love it, maybe most people won't even notice ))). Thank you very much again. @Geobert , you should be a hero for Rust developers. If they will adopt this extension of course ))).
Meanwhile, I think, I'll refactor namespace
to scope
. Maybe it will help to avoid some misunderstandings in future. scope
is more general and can be applied to namespace, module, package, outer class, etc.
Hi! I'll open one ticket per issue to keep the discussions targeted :) Hope you don't mind.
In the previous ticket, I didn't pay attention to one thing I've noticed this morning while testing the new version:![image](https://user-images.githubusercontent.com/72570/58464212-338e8380-812d-11e9-9fb5-c7c6bd73209d.png)
WebEvent
is properly coloured as a type on its declaration, but not when using the variants in thematch
statement.Same thing here:![image](https://user-images.githubusercontent.com/72570/58464575-d7782f00-812d-11e9-8395-e107c496293c.png)
HexView
is astruct
(a type) and is coloured as a namespace.