File: utils.rs

package info (click to toggle)
rust-lopdf 0.34.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,620 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use lopdf::{Document, IncrementalDocument, Result};
use std::fmt::Display;
use std::path::Path;

#[allow(dead_code)]
pub fn load_document<P>(path: P) -> Result<Document>
where
    P: AsRef<Path> + Display,
{
    #[cfg(feature = "async")]
    let doc = tokio::runtime::Runtime::new()?
        .block_on(async move { Document::load(&path).await.expect(&*format!("Failed to load {}", path)) });
    #[cfg(not(feature = "async"))]
    let doc = Document::load(path)?;

    Ok(doc)
}

#[allow(dead_code)]
pub fn load_incremental_document<P>(path: P) -> Result<IncrementalDocument>
where
    P: AsRef<Path> + Display,
{
    #[cfg(feature = "async")]
    let doc = tokio::runtime::Runtime::new()?.block_on(async move {
        IncrementalDocument::load(&path)
            .await
            .expect(&*format!("Failed to load {}", path))
    });
    #[cfg(not(feature = "async"))]
    let doc = IncrementalDocument::load(path)?;

    Ok(doc)
}