Inheritance for beginners

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

Your code snippet is utterly cluttered, because of your comments. Please remove them to make the actual code small and readable. (I don't want to scroll for three minutes to see your whole code. I can read code and know which function calls).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.