@@ -272,7 +272,7 @@ pub trait DeviceConfig {
272
272
}
273
273
274
274
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize , Validate ) ]
275
- #[ serde( default ) ]
275
+ #[ serde( default , rename_all = "camelCase" ) ]
276
276
pub struct Dummy {
277
277
#[ validate( range( min = 1 ) ) ]
278
278
pub hardware_led_count : u32 ,
@@ -1374,6 +1374,8 @@ impl InstanceConfigCreator {
1374
1374
1375
1375
#[ derive( Debug , Error ) ]
1376
1376
pub enum ConfigError {
1377
+ #[ error( "i/o error: {0}" ) ]
1378
+ Io ( #[ from] std:: io:: Error ) ,
1377
1379
#[ error( "error querying the database: {0}" ) ]
1378
1380
Sqlx ( #[ from] sqlx:: Error ) ,
1379
1381
#[ error( "error loading instance: {0}" ) ]
@@ -1387,6 +1389,8 @@ pub enum ConfigError {
1387
1389
// TODO: Say which setting?
1388
1390
#[ error( "missing hyperion_inst field on instance setting" ) ]
1389
1391
MissingHyperionInst ,
1392
+ #[ error( "invalid JSON: {0}" ) ]
1393
+ Json ( #[ from] serde_json:: Error ) ,
1390
1394
}
1391
1395
1392
1396
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
@@ -1601,6 +1605,16 @@ impl Config {
1601
1605
} )
1602
1606
}
1603
1607
1608
+ pub async fn load_file ( path : & std:: path:: Path ) -> Result < Self , ConfigError > {
1609
+ use tokio:: io:: AsyncReadExt ;
1610
+
1611
+ let mut file = tokio:: fs:: File :: open ( path) . await ?;
1612
+ let mut full = String :: new ( ) ;
1613
+ file. read_to_string ( & mut full) . await ?;
1614
+
1615
+ Ok ( serde_json:: from_str ( & full) ?)
1616
+ }
1617
+
1604
1618
pub fn uuid ( & self ) -> uuid:: Uuid {
1605
1619
// There should always be a meta uuid
1606
1620
self . meta . first ( ) . map ( |meta| meta. uuid ) . unwrap_or_default ( )
0 commit comments