More ergonomic api when STD is available
This commit is contained in:
		
							parent
							
								
									625baa72a3
								
							
						
					
					
						commit
						117c36ee61
					
				
					 3 changed files with 17 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -54,6 +54,14 @@ pub struct Matter<'a> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
impl<'a> Matter<'a> {
 | 
			
		||||
    #[cfg(feature = "std")]
 | 
			
		||||
    pub fn new_default(dev_det: &'a BasicInfoConfig, mdns: &'a mut dyn Mdns) -> Self {
 | 
			
		||||
        use crate::utils::epoch::{sys_epoch, sys_utc_calendar};
 | 
			
		||||
        use crate::utils::rand::sys_rand;
 | 
			
		||||
 | 
			
		||||
        Self::new(dev_det, mdns, sys_epoch, sys_rand, sys_utc_calendar)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Creates a new Matter object
 | 
			
		||||
    ///
 | 
			
		||||
    /// # Parameters
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -191,18 +191,18 @@ impl<'a> TransportMgr<'a> {
 | 
			
		|||
    pub fn new<
 | 
			
		||||
        T: Borrow<RefCell<FabricMgr>>
 | 
			
		||||
            + Borrow<RefCell<PaseMgr>>
 | 
			
		||||
            + Borrow<RefCell<MdnsMgr<'a>>>
 | 
			
		||||
            + Borrow<Epoch>
 | 
			
		||||
            + Borrow<Rand>
 | 
			
		||||
            + Borrow<UtcCalendar>,
 | 
			
		||||
    >(
 | 
			
		||||
        matter: &'a T,
 | 
			
		||||
        mdns_mgr: &'a RefCell<MdnsMgr<'a>>,
 | 
			
		||||
    ) -> Self {
 | 
			
		||||
        Self::wrap(
 | 
			
		||||
            SecureChannel::new(
 | 
			
		||||
                matter.borrow(),
 | 
			
		||||
                matter.borrow(),
 | 
			
		||||
                mdns_mgr,
 | 
			
		||||
                matter.borrow(),
 | 
			
		||||
                *matter.borrow(),
 | 
			
		||||
                *matter.borrow(),
 | 
			
		||||
            ),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,10 @@
 | 
			
		|||
pub type Rand = fn(&mut [u8]);
 | 
			
		||||
 | 
			
		||||
pub fn dummy_rand(_buf: &mut [u8]) {}
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "std")]
 | 
			
		||||
pub fn sys_rand(buf: &mut [u8]) {
 | 
			
		||||
    use rand::{thread_rng, RngCore};
 | 
			
		||||
 | 
			
		||||
    thread_rng().fill_bytes(buf);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue