Hi kpreid,
In fact, I analyse a lot and I think my problem comes from typst-as-lib crate that I use.
I explain what is happening, and I would like to understand how to manage the edition and the rust version in a second step if you understand my incomprehension.
So to reproduce my problem : I try to run a sample just to test typst-as-lib.
Cargo.toml that makes the sample works
I take a old version(0.13.0) of typst-as-lib and I use 2018 edition. I compile with rust 1.82.0 version.
[package]
name = "Test" # the name of the package
version = "0.0.1"
edition = "2018"
[dependencies]
derive_typst_intoval = "0.3.0"
typst = "0.13.1"
typst-as-lib = "0.13.0"
typst-pdf = "0.13.1"
But if I use this version of Cargo.toml, it does not works because a problem occurs in typst lib that is used in typst-as-lib.
Cargo.toml that makes the sample NOT working
I take the lastest version(0.14.4) of typst-as-lib and I use 2024 edition. I compile with rust 1.86.0 version.
[package]
name = "Test" # the name of the package
version = "0.0.1"
edition = "2024"
[dependencies]
derive_typst_intoval = "0.3.0"
typst = "0.13.1"
typst-as-lib = "0.14.4"
typst-pdf = "0.13.1"
The others files of my test :
src>main.rs The example in typst-as-lib without image, just to test quickly.
use derive_typst_intoval::{IntoDict, IntoValue};
use std::fs;
use typst::foundations::{Bytes, Dict, IntoValue};
use typst_as_lib::TypstEngine;
static TEMPLATE_FILE: &str = include_str!("./templates/template.typ");
static FONT: &[u8] = include_bytes!("./fonts/texgyrecursor-regular.otf");
static OUTPUT: &str = "./output.pdf";
fn main() {
// Read in fonts and the main source file.
// We can use this template more than once, if needed (Possibly
// with different input each time).
let template = TypstEngine::builder()
.main_file(TEMPLATE_FILE)
.fonts([FONT])
.build();
// Run it
let doc = template
.compile_with_input(dummy_data())
.output
.expect("typst::compile() returned an error!");
// Create pdf
let options = Default::default();
let pdf = typst_pdf::pdf(&doc, &options).expect("Could not generate pdf.");
fs::write(OUTPUT, pdf).expect("Could not write pdf.");
}
// Some dummy content. We use `derive_typst_intoval` to easily
// create `Dict`s from structs by deriving `IntoDict`;
fn dummy_data() -> Content {
Content {
v: vec![
ContentElement {
heading: "Foo".to_owned(),
text: Some("Hello World!".to_owned()),
num1: 1,
num2: Some(42),
image: None,
},
ContentElement {
heading: "Bar".to_owned(),
num1: 2,
..Default::default()
},
],
}
}
#[derive(Debug, Clone, IntoValue, IntoDict)]
struct Content {
v: Vec<ContentElement>,
}
// Implement Into<Dict> manually, so we can just pass the struct
// to the compile function.
impl From<Content> for Dict {
fn from(value: Content) -> Self {
value.into_dict()
}
}
#[derive(Debug, Clone, Default, IntoValue, IntoDict)]
struct ContentElement {
heading: String,
text: Option<String>,
num1: i32,
num2: Option<i32>,
image: Option<Bytes>,
}
src>templates>template.typ
#import sys: inputs
#set page(paper: "a4")
#set text(font: "TeX Gyre Cursor", 11pt)
#let content = inputs.v
#let last_index = content.len() - 1
#for (i, elem) in content.enumerate() [
== #elem.heading
Text: #elem.text \
Num1: #elem.num1 \
Num2: #elem.num2 \
#if i < last_index [
#pagebreak()
]
]
src>fonts>texgyrecursor-regular.otf
This file -> typst-as-lib/examples/fonts/texgyrecursor-regular.otf at main · Relacibo/typst-as-lib · GitHub
The error lets me thinking that the typst crate has a error compilation too now (It used to works but I get the code of typst-as-lib and try to run a sample just now and it does not works too...):
cargo run
Blocking waiting for file lock on build directory
Compiling typst-library v0.13.1
Compiling typst v0.12.0
error[E0412]: cannot find type `HashMap` in this scope
--> ....cargo\registry\src\index.crates.io-1949cf8c6b5b557f\typst-0.12.0\src\foundations\value.rs:94:13
|
94 | HashMap(HashMap<K, V>),
| ^^^^^^^ not found in this scope
|
help: consider importing this struct
|
1 + use std::collections::HashMap;
...
So, if I used a old version of rust to compile, I need to use the previous edition 2018 and so a old version of typst-of-lib (0.13.0 for example).
But if I want to make my big project updated, I will need to use latest version of crate, and so latest edition in future...
And now this crate typst-of-lib needs a crate named typst that not compil in 1.86.0 version... with 2024 edition...
But my incomprehension comes that I used a example with 2024 edition before using this crate one month ago. I try my sample yesterday, It works. I just use command cargo update
and now, nothing works anymore. I delete Cargo.lock, clean target... And try the original code from the typst-as-lib, and nothing run.
???