src/section_config.rs: add lookup_json() helper
This commit is contained in:
		@ -61,22 +61,23 @@ impl SectionConfigData {
 | 
				
			|||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn lookup<T: DeserializeOwned>(&self, type_name: &str, id: &str) -> Result<T, Error> {
 | 
					    pub fn lookup_json(&self, type_name: &str, id: &str) -> Result<Value, Error> {
 | 
				
			||||||
 | 
					        match self.sections.get(id) {
 | 
				
			||||||
        let config = match self.sections.get(id) {
 | 
					 | 
				
			||||||
            Some((section_type_name, config)) => {
 | 
					            Some((section_type_name, config)) => {
 | 
				
			||||||
                if type_name != section_type_name {
 | 
					                if type_name != section_type_name {
 | 
				
			||||||
                    bail!("got unexpected type '{}' for {} '{}'", section_type_name, type_name, id);
 | 
					                    bail!("got unexpected type '{}' for {} '{}'", section_type_name, type_name, id);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                config
 | 
					                Ok(config.clone())
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            None => {
 | 
					            None => {
 | 
				
			||||||
                bail!("no such {} '{}'", type_name, id);
 | 
					                bail!("no such {} '{}'", type_name, id);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
        let data = T::deserialize(config.clone())?;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn lookup<T: DeserializeOwned>(&self, type_name: &str, id: &str) -> Result<T, Error> {
 | 
				
			||||||
 | 
					        let config = self.lookup_json(type_name, id)?;
 | 
				
			||||||
 | 
					        let data = T::deserialize(config)?;
 | 
				
			||||||
        Ok(data)
 | 
					        Ok(data)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user