0

i have project like this:

├── Cargo.toml
└── src
    ├── bin
    │   ├── api_function_one.rs
    │   └── api_function_two.rs
    └── main.rs

Cargo.toml

[package]
name = "example"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "function_one"
path = "src/bin/api_function_one.rs"

[[bin]]
name = "function_two"
path = "src/bin/api_function_two.rs"

[dependencies]
diesel = { version = "2.0.0", features = ["postgres", "chrono", "uuid"] }

How can i call from src/main.rs functions from src/bin/?

I need binary functions, but i don't know, how to invoke them... If it impossible for binary project, can I do it in library project?

i read this:

  • 2
    "How can i call from src/main.rs functions from src/bin/?" you don't, you move the common behaviour into a `lib.rs`, and import it from any / all binaries which need them. Something like [this](https://stackoverflow.com/questions/26946646/package-with-both-a-library-and-a-binary). You don't even need to declare any of them in your `Cargo,toml` because Cargo automatically looks up the contents of `src/bin` and assumes all of them are individual binaries. [Example](https://github.com/masklinn/xls2txt/tree/master). – Masklinn Apr 20 '23 at 12:40
  • Do you need `api_function_one` and `api_function_two` to be separate executables in addition to them being called from `main`? – Jmb Apr 20 '23 at 14:00
  • @Jmb yes, you're right – Dmitry Mustache Apr 22 '23 at 08:20
  • Can wasm help me with this problem? https://www.rust-lang.org/what/wasm – Dmitry Mustache Apr 22 '23 at 13:59

0 Answers0