What I want to do is to safely get an object from a crate not called in my main() but in one of my sub libraries. Example:
crate crt
^
| xx calls crt
|
// This my initial lib crate called xx :
use crt::{make_a};
// crt::Res is not accessible from my
// main function it is something closed
// up deep in the code
use crt:Res;
pub struct A {
pub a: crt:Res<Conf>
}
impl A {
pub fn get(self)-> crt:Res<Conf> {
self.a
}
}
pub trait AA {
fn new ()-> Self;
}
impl AA for A {
fn new()->Self{
// make_a is a constructor in crt
// that knows how to make crt:Res<Conf>
A{a: make_a()}
}
}
^
| XX calls xx
|
// This is my second lib crate called XX
use xx::A;
pub fn pass-> A{
let p : A = AA::new();
p
}
// I can pass object A to my main function which latter calls my library XX and do something like :
^
| main() calls XX
|
// This is my main ()
use XX;
fn main(){
let a = XX::pass();
println!({:#?}, a.a);
}
but this seams stupid because I am directly accessing to a variable in my structure and not through some safe get()
function. I tried to implement get()
in various ways but, it seams that unless i call :
use crt::Res
directly in my main, I cannot do anything with it. Is there a better safer way to get to a.a without calling crt crate directly in main()
.
Thank you
PS
the code is for concept illustration mainly