More ergonomic api when STD is available

This commit is contained in:
ivmarkov 2023-04-24 09:26:04 +00:00
parent 625baa72a3
commit 117c36ee61
3 changed files with 17 additions and 2 deletions

View file

@ -54,6 +54,14 @@ pub struct Matter<'a> {
} }
impl<'a> 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 /// Creates a new Matter object
/// ///
/// # Parameters /// # Parameters

View file

@ -191,18 +191,18 @@ impl<'a> TransportMgr<'a> {
pub fn new< pub fn new<
T: Borrow<RefCell<FabricMgr>> T: Borrow<RefCell<FabricMgr>>
+ Borrow<RefCell<PaseMgr>> + Borrow<RefCell<PaseMgr>>
+ Borrow<RefCell<MdnsMgr<'a>>>
+ Borrow<Epoch> + Borrow<Epoch>
+ Borrow<Rand> + Borrow<Rand>
+ Borrow<UtcCalendar>, + Borrow<UtcCalendar>,
>( >(
matter: &'a T, matter: &'a T,
mdns_mgr: &'a RefCell<MdnsMgr<'a>>,
) -> Self { ) -> Self {
Self::wrap( Self::wrap(
SecureChannel::new( SecureChannel::new(
matter.borrow(), matter.borrow(),
matter.borrow(), matter.borrow(),
mdns_mgr, matter.borrow(),
*matter.borrow(), *matter.borrow(),
*matter.borrow(), *matter.borrow(),
), ),

View file

@ -1,3 +1,10 @@
pub type Rand = fn(&mut [u8]); pub type Rand = fn(&mut [u8]);
pub fn dummy_rand(_buf: &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);
}