Skip to content

Commit aabc96d

Browse files
committed
ruff integration support
1 parent 99e108d commit aabc96d

File tree

4 files changed

+268
-232
lines changed

4 files changed

+268
-232
lines changed

ast/src/builtin.rs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,33 @@ impl Identifier {
1313
pub fn new(s: impl Into<String>) -> Self {
1414
Self(s.into())
1515
}
16+
}
17+
18+
impl std::cmp::PartialEq<str> for Identifier {
1619
#[inline]
17-
pub fn as_str(&self) -> &str {
18-
self.0.as_str()
20+
fn eq(&self, other: &str) -> bool {
21+
self.0 == other
1922
}
2023
}
2124

22-
impl std::string::ToString for Identifier {
25+
impl std::cmp::PartialEq<String> for Identifier {
2326
#[inline]
24-
fn to_string(&self) -> String {
25-
self.0.clone()
27+
fn eq(&self, other: &String) -> bool {
28+
&self.0 == other
29+
}
30+
}
31+
32+
impl std::ops::Deref for Identifier {
33+
type Target = String;
34+
#[inline]
35+
fn deref(&self) -> &Self::Target {
36+
&self.0
37+
}
38+
}
39+
40+
impl std::fmt::Display for Identifier {
41+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42+
self.0.fmt(f)
2643
}
2744
}
2845

@@ -33,24 +50,46 @@ impl From<Identifier> for String {
3350
}
3451
}
3552

36-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
53+
impl From<String> for Identifier {
54+
#[inline]
55+
fn from(id: String) -> Self {
56+
Self(id)
57+
}
58+
}
59+
60+
impl<'a> From<&'a str> for Identifier {
61+
#[inline]
62+
fn from(id: &'a str) -> Identifier {
63+
id.to_owned().into()
64+
}
65+
}
66+
67+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
3768
pub struct Int(u32);
3869

3970
impl Int {
4071
pub fn new(i: u32) -> Self {
4172
Self(i)
4273
}
43-
pub fn new_bool(i: bool) -> Self {
44-
Self(i as u32)
45-
}
4674
pub fn to_u32(&self) -> u32 {
4775
self.0
4876
}
4977
pub fn to_usize(&self) -> usize {
5078
self.0 as _
5179
}
52-
pub fn to_bool(&self) -> bool {
53-
self.0 > 0
80+
}
81+
82+
impl std::cmp::PartialEq<u32> for Int {
83+
#[inline]
84+
fn eq(&self, other: &u32) -> bool {
85+
self.0 == *other
86+
}
87+
}
88+
89+
impl std::cmp::PartialEq<usize> for Int {
90+
#[inline]
91+
fn eq(&self, other: &usize) -> bool {
92+
self.0 as usize == *other
5493
}
5594
}
5695

@@ -165,11 +204,11 @@ impl<T, U> Attributed<T, U> {
165204

166205
impl<T> Attributed<T, ()> {
167206
/// Creates a new node that spans the position specified by `range`.
168-
pub fn new(range: impl Into<TextRange>, node: T) -> Self {
207+
pub fn new(range: impl Into<TextRange>, node: impl Into<T>) -> Self {
169208
Self {
170209
range: range.into(),
171210
custom: (),
172-
node,
211+
node: node.into(),
173212
}
174213
}
175214

0 commit comments

Comments
 (0)