pub fn open_image(path: &str) -> Result<(), Error>Expand description
Opens an image file with the default image viewer of the system.
This function checks if the provided path exists and then opens the image file using the appropriate command based on the operating system.
§Arguments
path- A string slice that holds the path to the image file.
§OS Specific Behavior
- Windows: Uses
cmd /c startto open the image. - Linux: Uses
xdg-opento open the image. - macOS: Uses
opento open the image. - Other OS: Returns an
Errindicating that the OS is not supported.
§Errors
Returns an Err if the image file does not exist or if the command to open the image fails to spawn.
§Examples
use my_crate::open_image; // Replace with the actual path to your function
match open_image("/path/to/image.png") {
Ok(_) => println!("Image opened successfully"),
Err(e) => println!("Failed to open image: {}", e),
}