Skip to content

Commit 249b1ee

Browse files
authored
new() -> Self (#35)
1 parent 0b5f74e commit 249b1ee

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

bin/weldr/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub struct Utf8Error {
127127

128128
impl Utf8Error {
129129
pub fn new(context: &str) -> Self {
130-
Utf8Error {
130+
Self {
131131
context: context.to_string(),
132132
}
133133
}

bin/weldr/src/gltf.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ pub struct Mesh {
216216
}
217217

218218
impl Gltf {
219-
pub fn new(asset: Asset) -> Gltf {
220-
Gltf {
219+
pub fn new(asset: Asset) -> Self {
220+
Self {
221221
asset,
222222
nodes: vec![],
223223
scenes: vec![],
@@ -238,8 +238,8 @@ impl Gltf {
238238
}
239239

240240
impl Asset {
241-
pub fn new(version: &str) -> Asset {
242-
Asset {
241+
pub fn new(version: &str) -> Self {
242+
Self {
243243
version: version.to_string(),
244244
min_version: None,
245245
generator: None,
@@ -270,8 +270,8 @@ impl Asset {
270270
}
271271

272272
impl Buffer {
273-
pub fn new(byte_length: u32) -> Buffer {
274-
Buffer {
273+
pub fn new(byte_length: u32) -> Self {
274+
Self {
275275
name: None,
276276
byte_length,
277277
uri: None,

bin/weldr/src/weldr.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ struct SimpleLogger {
5959
static mut LOGGER: SimpleLogger = SimpleLogger::new();
6060

6161
impl SimpleLogger {
62-
const fn new() -> SimpleLogger {
63-
SimpleLogger {
62+
const fn new() -> Self {
63+
Self {
6464
log_level: log::LevelFilter::Info,
6565
color_enabled: false,
6666
emoji_enabled: false,
@@ -183,19 +183,19 @@ struct DiskResolver {
183183
}
184184

185185
impl DiskResolver {
186-
fn new() -> DiskResolver {
187-
DiskResolver { base_paths: vec![] }
186+
fn new() -> Self {
187+
Self { base_paths: vec![] }
188188
}
189189

190-
fn new_from_catalog<P: AsRef<Path>>(catalog_path: P) -> Result<DiskResolver, Error> {
190+
fn new_from_catalog<P: AsRef<Path>>(catalog_path: P) -> Result<Self, Error> {
191191
let catalog_path = std::fs::canonicalize(catalog_path)
192192
.map_err(|e| Error::NotFound(format!("catalog path not found ({})", e)))?;
193193
let base_paths = vec![
194194
catalog_path.join("p"),
195195
catalog_path.join("parts"),
196196
catalog_path.join("parts").join("s"),
197197
];
198-
Ok(DiskResolver { base_paths })
198+
Ok(Self { base_paths })
199199
}
200200

201201
fn add_path<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error> {
@@ -280,8 +280,8 @@ struct GeometryCache {
280280
}
281281

282282
impl GeometryCache {
283-
fn new() -> GeometryCache {
284-
GeometryCache {
283+
fn new() -> Self {
284+
Self {
285285
vertices: vec![],
286286
vertex_map: HashMap::new(),
287287
line_indices: vec![],

lib/src/error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct ResolveError {
3636
impl ParseError {
3737
/// Create a [`ParseError`] that stems from an arbitrary error of an underlying parser.
3838
pub fn new(filename: &str, err: impl Into<Box<dyn std::error::Error>>) -> Self {
39-
ParseError {
39+
Self {
4040
filename: filename.to_string(),
4141
parse_error: Some(err.into()),
4242
}
@@ -45,7 +45,7 @@ impl ParseError {
4545
/// Create a [`ParseError`] that stems from a [`nom`] parsing error, capturing the [`nom::error::ErrorKind`]
4646
/// from the underlying parser which failed.
4747
pub fn new_from_nom(filename: &str, err: &nom::Err<nom::error::Error<&[u8]>>) -> Self {
48-
ParseError {
48+
Self {
4949
filename: filename.to_string(),
5050
parse_error: match err {
5151
nom::Err::Incomplete(_) => None,
@@ -65,15 +65,15 @@ impl ParseError {
6565
impl ResolveError {
6666
/// Create a [`ResolveError`] that stems from an arbitrary error of an underlying resolution error.
6767
pub fn new(filename: String, err: impl Into<Box<dyn std::error::Error>>) -> Self {
68-
ResolveError {
68+
Self {
6969
filename,
7070
resolve_error: Some(err.into()),
7171
}
7272
}
7373

7474
/// Create a [`ResolveError`] without any underlying error.
7575
pub fn new_raw(filename: &str) -> Self {
76-
ResolveError {
76+
Self {
7777
filename: filename.to_string(),
7878
resolve_error: None,
7979
}

lib/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ pub struct Color {
9090

9191
impl Color {
9292
/// Construct a new color instance from individual RGB components.
93-
pub fn new(red: u8, green: u8, blue: u8) -> Color {
94-
Color { red, green, blue }
93+
pub fn new(red: u8, green: u8, blue: u8) -> Self {
94+
Self { red, green, blue }
9595
}
9696
}
9797

@@ -393,8 +393,8 @@ pub struct CommentCmd {
393393
}
394394

395395
impl CommentCmd {
396-
pub fn new(text: &str) -> CommentCmd {
397-
CommentCmd {
396+
pub fn new(text: &str) -> Self {
397+
Self {
398398
text: text.to_string(),
399399
}
400400
}
@@ -457,8 +457,8 @@ pub struct SourceMap {
457457

458458
impl SourceMap {
459459
/// Construct a new empty source map.
460-
pub fn new() -> SourceMap {
461-
SourceMap {
460+
pub fn new() -> Self {
461+
Self {
462462
source_files: HashMap::new(),
463463
}
464464
}

lib/tests/parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct MemoryResolver {
2020
}
2121

2222
impl MemoryResolver {
23-
fn new() -> MemoryResolver {
24-
MemoryResolver {
23+
fn new() -> Self {
24+
Self {
2525
file_map: HashMap::new(),
2626
}
2727
}

0 commit comments

Comments
 (0)