Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::Arc;
- use std::sync::Mutex;
- #[derive(Debug)]
- struct AppState {
- services: Option<Arc<Mutex<AppServices>>>,
- }
- impl AppState {
- pub fn new() -> Self {
- AppState {
- services: None,
- }
- }
- pub fn set_services(&mut self, services: Option<Arc<Mutex<AppServices>>>){
- self.services = services;
- }
- }
- #[derive(Debug)]
- struct AppServices {
- id: IdService,
- }
- #[derive(Debug)]
- struct IdService {
- name: String,
- state: Arc<Mutex<AppState>>,
- }
- fn main() {
- let app_state = AppState::new();
- let arc = Arc::new(Mutex::new(app_state));
- let id_service = IdService {
- name: "test".to_string(),
- state: arc.clone(),
- };
- let app_services = AppServices {
- id: id_service,
- };
- let mut app_state_ref = arc.lock().unwrap();
- app_state_ref.set_services(Some(Arc::new(Mutex::new(app_services))));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement