Skip to main content

pdfium_render/pdf/action/
local_destination.rs

1//! Defines the [PdfActionLocalDestination] struct, exposing functionality related to a single
2//! action of type `PdfActionType::GoToDestinationInSameDocument`.
3
4use crate::bindgen::{FPDF_ACTION, FPDF_DOCUMENT};
5use crate::error::{PdfiumError, PdfiumInternalError};
6use crate::pdf::action::private::internal::PdfActionPrivate;
7use crate::pdf::destination::PdfDestination;
8use crate::pdfium::PdfiumLibraryBindingsAccessor;
9use std::marker::PhantomData;
10
11pub struct PdfActionLocalDestination<'a> {
12    handle: FPDF_ACTION,
13    document: FPDF_DOCUMENT,
14    lifetime: PhantomData<&'a FPDF_ACTION>,
15}
16
17impl<'a> PdfActionLocalDestination<'a> {
18    #[inline]
19    pub(crate) fn from_pdfium(handle: FPDF_ACTION, document: FPDF_DOCUMENT) -> Self {
20        PdfActionLocalDestination {
21            handle,
22            document,
23            lifetime: PhantomData,
24        }
25    }
26
27    /// Returns the target [PdfDestination] for this [PdfActionLocalDestination].
28    pub fn destination(&self) -> Result<PdfDestination<'_>, PdfiumError> {
29        let handle = unsafe {
30            self.bindings()
31                .FPDFAction_GetDest(self.document, self.handle)
32        };
33
34        if handle.is_null() {
35            Err(PdfiumError::PdfiumLibraryInternalError(
36                PdfiumInternalError::Unknown,
37            ))
38        } else {
39            Ok(PdfDestination::from_pdfium(self.document, handle))
40        }
41    }
42}
43
44impl<'a> PdfActionPrivate<'a> for PdfActionLocalDestination<'a> {
45    #[inline]
46    fn handle(&self) -> &FPDF_ACTION {
47        &self.handle
48    }
49}
50
51impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfActionLocalDestination<'a> {}
52
53#[cfg(feature = "thread_safe")]
54unsafe impl<'a> Send for PdfActionLocalDestination<'a> {}
55
56#[cfg(feature = "thread_safe")]
57unsafe impl<'a> Sync for PdfActionLocalDestination<'a> {}