pub struct Kpathsea { /* private fields */ }Expand description
A configured kpathsea instance.
Implementations§
Source§impl Kpathsea
impl Kpathsea
Sourcepub fn set_output_directory(&mut self, dir: Option<String>)
pub fn set_output_directory(&mut self, dir: Option<String>)
The output directory that stands for TEXMF_OUTPUT_DIRECTORY in the
checks of Kpathsea::name_ok, instead of the environment’s: LuaTeX
sets the variable from -output-directory.
Source§impl Kpathsea
impl Kpathsea
Sourcepub fn new(options: Options) -> Result<Self, Error>
pub fn new(options: Options) -> Result<Self, Error>
Initializes kpathsea from the process environment.
Examples found in repository?
examples/kpsewhich.rs (line 13)
4fn main() {
5 let args: Vec<String> = std::env::args().collect();
6 let fmt = match args.get(1).map(String::as_str) {
7 Some("lua") => FileFormat::Lua,
8 Some("fmt") => FileFormat::Fmt,
9 Some("otf") => FileFormat::OpenType,
10 Some("tfm") => FileFormat::Tfm,
11 _ => FileFormat::Tex,
12 };
13 let mut k = Kpathsea::new(Options::lualatex()).unwrap();
14 let t = std::time::Instant::now();
15 let found = k.find_file(&args[2], fmt);
16 eprintln!("path: {:?}", k.search_path(fmt));
17 println!("{found:?} ({:?})", t.elapsed());
18}More examples
examples/kpsetime.rs (line 8)
4fn main() {
5 let t = std::time::Instant::now();
6 let mut o = Options::lualatex();
7 o.cache_dir = Some(std::env::temp_dir().join("retex-kpse-test"));
8 let mut k = Kpathsea::new(o).unwrap();
9 let init = t.elapsed();
10 let t = std::time::Instant::now();
11 for n in [
12 "latex.ltx",
13 "article.cls",
14 "size10.clo",
15 "lmroman10-regular.otf",
16 "ltluatex.lua",
17 ] {
18 let f = if n.ends_with(".otf") {
19 FileFormat::OpenType
20 } else if n.ends_with(".lua") {
21 FileFormat::Lua
22 } else {
23 FileFormat::Tex
24 };
25 let _ = k.find_file(n, f);
26 }
27 println!("init {init:?}, 5 lookups {:?}", t.elapsed());
28}Sourcepub fn with_env(options: Options, env: Box<dyn Env>) -> Result<Self, Error>
pub fn with_env(options: Options, env: Box<dyn Env>) -> Result<Self, Error>
Initializes kpathsea with a custom environment.
Sourcepub fn var_value(&self, name: &str) -> Option<String>
pub fn var_value(&self, name: &str) -> Option<String>
Returns the expanded value of variable name, like
kpsewhich -var-value. Braces are not expanded.
Sourcepub fn search_path(&mut self, format: FileFormat) -> &[String]
pub fn search_path(&mut self, format: FileFormat) -> &[String]
The fully expanded search path for format, one element per entry.
Elements may start with !! and contain //.
Examples found in repository?
examples/kpsewhich.rs (line 16)
4fn main() {
5 let args: Vec<String> = std::env::args().collect();
6 let fmt = match args.get(1).map(String::as_str) {
7 Some("lua") => FileFormat::Lua,
8 Some("fmt") => FileFormat::Fmt,
9 Some("otf") => FileFormat::OpenType,
10 Some("tfm") => FileFormat::Tfm,
11 _ => FileFormat::Tex,
12 };
13 let mut k = Kpathsea::new(Options::lualatex()).unwrap();
14 let t = std::time::Instant::now();
15 let found = k.find_file(&args[2], fmt);
16 eprintln!("path: {:?}", k.search_path(fmt));
17 println!("{found:?} ({:?})", t.elapsed());
18}Sourcepub fn find_file(&mut self, name: &str, format: FileFormat) -> Option<PathBuf>
pub fn find_file(&mut self, name: &str, format: FileFormat) -> Option<PathBuf>
Finds the first file matching name in the search path of format,
like kpsewhich -format=… name.
Examples found in repository?
examples/kpsewhich.rs (line 15)
4fn main() {
5 let args: Vec<String> = std::env::args().collect();
6 let fmt = match args.get(1).map(String::as_str) {
7 Some("lua") => FileFormat::Lua,
8 Some("fmt") => FileFormat::Fmt,
9 Some("otf") => FileFormat::OpenType,
10 Some("tfm") => FileFormat::Tfm,
11 _ => FileFormat::Tex,
12 };
13 let mut k = Kpathsea::new(Options::lualatex()).unwrap();
14 let t = std::time::Instant::now();
15 let found = k.find_file(&args[2], fmt);
16 eprintln!("path: {:?}", k.search_path(fmt));
17 println!("{found:?} ({:?})", t.elapsed());
18}More examples
examples/kpsetime.rs (line 25)
4fn main() {
5 let t = std::time::Instant::now();
6 let mut o = Options::lualatex();
7 o.cache_dir = Some(std::env::temp_dir().join("retex-kpse-test"));
8 let mut k = Kpathsea::new(o).unwrap();
9 let init = t.elapsed();
10 let t = std::time::Instant::now();
11 for n in [
12 "latex.ltx",
13 "article.cls",
14 "size10.clo",
15 "lmroman10-regular.otf",
16 "ltluatex.lua",
17 ] {
18 let f = if n.ends_with(".otf") {
19 FileFormat::OpenType
20 } else if n.ends_with(".lua") {
21 FileFormat::Lua
22 } else {
23 FileFormat::Tex
24 };
25 let _ = k.find_file(n, f);
26 }
27 println!("init {init:?}, 5 lookups {:?}", t.elapsed());
28}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Kpathsea
impl !Send for Kpathsea
impl !Sync for Kpathsea
impl !UnwindSafe for Kpathsea
impl Freeze for Kpathsea
impl Unpin for Kpathsea
impl UnsafeUnpin for Kpathsea
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more