Hello, i am writing blockchain and i faced an issue of importing functions from module.
unresolved import `super::anyencode`
could not find `anyencode` in the crate root
I tried "mod anyencode" but it didnt help.
I am newbie at rust, so i wanna ask you about help please.
I have such file structure
src/anyencode.rs (module i want to import)
src/element.rs (file where i try to import)
src/main.rs
Here is element.rs
use super::anyencode::{decode_data, encode_data};
use std::collections::HashMap;
#[derive(Debug)]
pub struct Element {
data: Vec<u8>,
neighbors: HashMap<String, String>,
hash: String,
extra_data: Vec<u8>,
memo: String,
}
impl Element {
pub fn new<T: std::fmt::Debug, U: std::fmt::Debug>(
data: T,
neighbors: HashMap<String, String>,
hash: String,
extra_data: U,
memo: String,
) -> Self {
let data = encode_data(&data).unwrap();
let extra_data = encode_data(&extra_data).unwrap();
Element {
data,
neighbors,
hash,
extra_data,
memo,
}
}
pub fn get_data<T: std::default::Default + std::clone::Clone>(&self) -> T {
decode_data::<T>(&self.data.clone()).unwrap_or_default()
}
pub fn get_extra_data<U: std::default::Default + std::clone::Clone>(&self) -> U {
decode_data::<U>(&self.extra_data.clone()).unwrap_or_default()
}
}
Thank you in advance.