magick_rust/types/
image.rs

1/*
2 * Copyright 2024 5ohue
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16use std::marker::PhantomData;
17
18use crate::bindings;
19
20pub struct Image<'a> {
21    image: *mut bindings::Image,
22    phantom_data: PhantomData<&'a bindings::Image>,
23}
24
25impl Image<'_> {
26    pub (crate) fn new(img: *mut bindings::Image) -> Self {
27        // SAFETY: This is safe and also does not require an Image::drop() call as:
28        //         The lifetime of Image is the same as the lifetime of wrapped bindings::Image.
29        //         The bindings::Image is borrowed by the caller from MagickWand.
30        //         Magickwand::drop() destroys the bindings::MagickWand, which
31        //         destroys both the associated bindings::Image and itself.
32        Image {
33            image: img,
34            phantom_data: PhantomData,
35        }
36    }
37
38    pub (crate) unsafe fn get_ptr(&self) -> *mut bindings::Image {
39        self.image
40    }
41}