More ergonomic api when STD is available

This commit is contained in:
ivmarkov 2023-04-24 09:26:04 +00:00
parent 505fa39e82
commit 688d7ea8d5
3 changed files with 17 additions and 2 deletions

View file

@ -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

View file

@ -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(),
),

View file

@ -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);
}