Repository: tauri-apps/tauri
File: core/tauri-codegen/src/image.rs (Rust)

Code before:
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use crate::embedded_assets::{ensure_out_dir, EmbeddedAssetsError, EmbeddedAssetsResult};
use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use std::path::Path;
use syn::{punctuated::Punctuated, Ident, PathArguments, PathSegment, Token};

pub fn icon_image_codegen(path: &Path) -> EmbeddedAssetsResult<TokenStream> {
  let out_dir = ensure_out_dir()?;
  let mut segments = Punctuated::new();
  segments.push(PathSegment {
    ident: Ident::new("tauri", Span::call_site()),
    arguments: PathArguments::None,
  });
  let root = syn::Path {
    leading_colon: Some(Token![::](Span::call_site())),
    segments,
  };
  image_icon(&root.to_token_stream(), &out_dir, path)
}

pub(crate) fn image_icon(
  root: &TokenStream,
  out_dir: &Path,
  path: &Path,
) -> EmbeddedAssetsResult<TokenStream> {
  let extension = path.extension().unwrap_or_default();
  if extension == "ico" {
    ico_icon(root, out_dir, path)
  } else if extension == "png" {
    png_icon(root, out_dir, path)
  } else {
    Err(EmbeddedAssetsError::InvalidImageExtension {
      extension: extension.into(),
      path: path.to_path_buf(),
    })
  }
}

pub(crate) fn raw_icon(out_dir: &Path, path: &Path) -> EmbeddedAssetsResult<TokenStream> {
  let bytes =
    std::fs::read(path).unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e));

  let out_path = out_dir.join(path.file_name().unwrap());

Review comment (suggestion):
```suggestion
  let out_dir = ensure_out_dir()?;

  let mut segments = Punctuated::new();
  segments.push(PathSegment {
    ident: Ident::new("tauri", Span::call_site()),
    arguments: PathArguments::None,
  });
  let root = syn::Path {
    leading_colon: Some(Token![::](Span::call_site())),
    segments,
  };

  image_icon(&root.to_token_stream(), &out_dir, path)
```

Code after:
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use crate::embedded_assets::{ensure_out_dir, EmbeddedAssetsError, EmbeddedAssetsResult};
use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use std::path::Path;
use syn::{punctuated::Punctuated, Ident, PathArguments, PathSegment, Token};

pub fn include_image_codegen(path: &Path) -> EmbeddedAssetsResult<TokenStream> {
  let out_dir = ensure_out_dir()?;

  let mut segments = Punctuated::new();
  segments.push(PathSegment {
    ident: Ident::new("tauri", Span::call_site()),
    arguments: PathArguments::None,
  });
  let root = syn::Path {
    leading_colon: Some(Token![::](Span::call_site())),
    segments,
  };

  image_icon(&root.to_token_stream(), &out_dir, path)
}

pub(crate) fn image_icon(
  root: &TokenStream,
  out_dir: &Path,
  path: &Path,
) -> EmbeddedAssetsResult<TokenStream> {
  let extension = path.extension().unwrap_or_default();
  if extension == "ico" {
    ico_icon(root, out_dir, path)
  } else if extension == "png" {
    png_icon(root, out_dir, path)
  } else {
    Err(EmbeddedAssetsError::InvalidImageExtension {
      extension: extension.into(),
      path: path.to_path_buf(),
    })
  }
}

pub(crate) fn raw_icon(out_dir: &Path, path: &Path) -> EmbeddedAssetsResult<TokenStream> {
  let bytes =
    std::fs::read(path).unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e));