Struct Image

Source
pub struct Image { /* private fields */ }
Expand description

A simple image loaded from NvDialog. This is the equivalent to NvdImage, although the implementation makes a few extra safety checks from the Rust side.

Implementations§

Source§

impl Image

Source

pub fn from_filename(filename: PathBuf) -> Result<Self, ImageError>

Creates an Image from a specified filename.

This function attempts to load an image from the given file path using NvDialog’s image loading facilities. It performs a few checks to ensure robustness and safety from the Rust side.

§Arguments
  • filename - A PathBuf specifying the file path of the image to be loaded.
§Returns
  • Result<Self, ImageError> - Returns an Ok variant containing the Image if successful, or an ImageError if an error occurs during the process.
§Errors
  • ImageError::PathNotFound - Returned if the file path does not exist.
  • ImageError::UnknownError - Returned if the image cannot be created from the data.
§Safety

This function makes use of unsafe blocks to interface with the C functions from NvDialog. It is assumed that nvd_image_from_filename and nvd_create_image are safe to call with the provided arguments.

Source

pub unsafe fn from_data( data: &[u8], width: u32, height: u32, ) -> Result<Self, ImageError>

Creates an Image from the raw data of an image file.

This function creates an Image from raw data that is assumed to be in a format that NvDialog can read. The data is sent to the NvDialog library without any checking on the Rust side, so it is left up to the user to ensure that the data is valid.

§Safety

This function is marked unsafe because the data passed to it is not checked in any way. If the data is not valid, it may cause undefined behavior when passed to the C library.

§Arguments
  • data - The raw image data. This is assumed to be the contents of an image file and should be in a format that NvDialog can read.
  • width - The width of the image in pixels.
  • height - The height of the image in pixels.
§Returns
  • Result<Self, ImageError> - Returns an Ok variant containing the Image if successful, or an ImageError if an error occurs.
§Errors
  • ImageError::InvalidFormat - Returned if the data is not in a valid format for NvDialog.
  • ImageError::UnknownError - Returned if the image cannot be created from the data for some other reason.

Trait Implementations§

Source§

impl Drop for Image

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl !Send for Image

§

impl !Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.