Skip to content
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

new() -> Self #35

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/weldr/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct Utf8Error {

impl Utf8Error {
pub fn new(context: &str) -> Self {
Utf8Error {
Self {
context: context.to_string(),
}
}
Expand Down
12 changes: 6 additions & 6 deletions bin/weldr/src/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ pub struct Mesh {
}

impl Gltf {
pub fn new(asset: Asset) -> Gltf {
Gltf {
pub fn new(asset: Asset) -> Self {
Self {
asset,
nodes: vec![],
scenes: vec![],
Expand All @@ -238,8 +238,8 @@ impl Gltf {
}

impl Asset {
pub fn new(version: &str) -> Asset {
Asset {
pub fn new(version: &str) -> Self {
Self {
version: version.to_string(),
min_version: None,
generator: None,
Expand Down Expand Up @@ -270,8 +270,8 @@ impl Asset {
}

impl Buffer {
pub fn new(byte_length: u32) -> Buffer {
Buffer {
pub fn new(byte_length: u32) -> Self {
Self {
name: None,
byte_length,
uri: None,
Expand Down
16 changes: 8 additions & 8 deletions bin/weldr/src/weldr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ struct SimpleLogger {
static mut LOGGER: SimpleLogger = SimpleLogger::new();

impl SimpleLogger {
const fn new() -> SimpleLogger {
SimpleLogger {
const fn new() -> Self {
Self {
log_level: log::LevelFilter::Info,
color_enabled: false,
emoji_enabled: false,
Expand Down Expand Up @@ -183,19 +183,19 @@ struct DiskResolver {
}

impl DiskResolver {
fn new() -> DiskResolver {
DiskResolver { base_paths: vec![] }
fn new() -> Self {
Self { base_paths: vec![] }
}

fn new_from_catalog<P: AsRef<Path>>(catalog_path: P) -> Result<DiskResolver, Error> {
fn new_from_catalog<P: AsRef<Path>>(catalog_path: P) -> Result<Self, Error> {
let catalog_path = std::fs::canonicalize(catalog_path)
.map_err(|e| Error::NotFound(format!("catalog path not found ({})", e)))?;
let base_paths = vec![
catalog_path.join("p"),
catalog_path.join("parts"),
catalog_path.join("parts").join("s"),
];
Ok(DiskResolver { base_paths })
Ok(Self { base_paths })
}

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

impl GeometryCache {
fn new() -> GeometryCache {
GeometryCache {
fn new() -> Self {
Self {
vertices: vec![],
vertex_map: HashMap::new(),
line_indices: vec![],
Expand Down
8 changes: 4 additions & 4 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct ResolveError {
impl ParseError {
/// Create a [`ParseError`] that stems from an arbitrary error of an underlying parser.
pub fn new(filename: &str, err: impl Into<Box<dyn std::error::Error>>) -> Self {
ParseError {
Self {
filename: filename.to_string(),
parse_error: Some(err.into()),
}
Expand All @@ -45,7 +45,7 @@ impl ParseError {
/// Create a [`ParseError`] that stems from a [`nom`] parsing error, capturing the [`nom::error::ErrorKind`]
/// from the underlying parser which failed.
pub fn new_from_nom(filename: &str, err: &nom::Err<nom::error::Error<&[u8]>>) -> Self {
ParseError {
Self {
filename: filename.to_string(),
parse_error: match err {
nom::Err::Incomplete(_) => None,
Expand All @@ -65,15 +65,15 @@ impl ParseError {
impl ResolveError {
/// Create a [`ResolveError`] that stems from an arbitrary error of an underlying resolution error.
pub fn new(filename: String, err: impl Into<Box<dyn std::error::Error>>) -> Self {
ResolveError {
Self {
filename,
resolve_error: Some(err.into()),
}
}

/// Create a [`ResolveError`] without any underlying error.
pub fn new_raw(filename: &str) -> Self {
ResolveError {
Self {
filename: filename.to_string(),
resolve_error: None,
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ pub struct Color {

impl Color {
/// Construct a new color instance from individual RGB components.
pub fn new(red: u8, green: u8, blue: u8) -> Color {
Color { red, green, blue }
pub fn new(red: u8, green: u8, blue: u8) -> Self {
Self { red, green, blue }
}
}

Expand Down Expand Up @@ -393,8 +393,8 @@ pub struct CommentCmd {
}

impl CommentCmd {
pub fn new(text: &str) -> CommentCmd {
CommentCmd {
pub fn new(text: &str) -> Self {
Self {
text: text.to_string(),
}
}
Expand Down Expand Up @@ -457,8 +457,8 @@ pub struct SourceMap {

impl SourceMap {
/// Construct a new empty source map.
pub fn new() -> SourceMap {
SourceMap {
pub fn new() -> Self {
Self {
source_files: HashMap::new(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct MemoryResolver {
}

impl MemoryResolver {
fn new() -> MemoryResolver {
MemoryResolver {
fn new() -> Self {
Self {
file_map: HashMap::new(),
}
}
Expand Down
Loading