The directory that contains everything is called p, in p is:
.git
.gitignore
Cargo.lock
Cargo.toml
todo.md
src
target
in src is:
action_functions.rs
execute_action_functions.rs
lib.rs
main.rs
network.r
in network.rs:
pub mod network{
use rand::Rng //to generate random numbers
//use crate::action_functions::{/*insert all the action functions */};
use rand_distr::{Normal, Distribution}; //to generate different dist. of random numbers
use serde::{Serialize, Deserialize}; //to save/load my neural network
use std::fs::File;
use std::io::{BufReader, BufWriter};
use chrono::Utc; //for timestamp
use std::path::Path; //for help in representing file paths
then I have a bunch of pub structs then I have impl NeuralNetwork { inside pub mod network with a bunch of pub functions.
in Cargo.toml:
[package]
name = "p"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"
rand_distr = "0.4.3"
serde_json = "1.0.108"
serde = {version = "1.0.193", features = ["derive"]}
chrono = "0.4"
in main.rs:
use crate::network::NeuralNetwork;
fn main() -> std::io::Result<()> {
let mut network = NeuralNetwork {
layers: Vec::new(),
weights: Vec::new(),
biases: Vec::new(),
};
network.initialization(10, 10, 2); // Initialize with your parameters
// Print the network
network.print();
// Save the network
network.save_v2()?;
// Load the network
//let path = "D:\\Downloads\\PxOmni\\rust_save_states\\your_file_name"; // Replace with your file path
//let loaded_network = NeuralNetwork::load(path)?;
// Print the loaded network
//loaded_network.print();
Ok(())
}
in lib.rs is:
pub mod network;
//pub mod Network;
pub mod action_functions;
pub mod execute_action_functions;
everything is code commented out in action_functions.rs except for:
pub mod action_functions {}
with everything code commented inside of action_functions, and the same goes for execute_action_functions. Just for transparency this is my execute_action_functions.rs:
pub mod execute_action_functions {}
and there's no errors detected by rust-analzer anywhere and no compilation errors. Except for this:
error[E0432]: unresolved import `crate::network`
--> src/main.rs:5:12
|
5 | use crate::network::NeuralNetwork;
| ^^^^^^^
| |
| unresolved import
| help: a similar path exists: `p::network`
And in main whenever I do:
use crate::p::network::NeuralNetwork;
it says:
error[E0433]: failed to resolve: could not find `p` in the crate root
--> src\main.rs:5:12
|
5 | use crate::p::network::NeuralNetwork;
| ^ could not find `p` in the crate root
For more information about this error, try `rustc --explain E0433`.
error: could not compile `p` (bin "p") due to previous error
I then tried to add a [[bin]] and do cargo run --bin your_binary_name and same error:
[[bin]]
name = "your_binary_name"
path = "src/main.rs"
I even tried adding:
[lib]
path = "src/lib.rs"
and no change.
You have two mistakes here.
The first is that
lib.rsandmain.rsare two different crates. If you want to accesslib.rsfrommain.rs, you cannot do that withcratebecause it's not the same crate; you have to use the crate name (p).The second is that
pub mod network;in lib.rs already creates a modulenetwork, if you dopub mod network { ... }inside network.rs you crate a nested module:p::network::network.