Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/hostcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,10 @@ extern "C" {
) -> Status;
}

pub fn get_property(path: Vec<&str>) -> Result<Option<Bytes>, Status> {
pub fn get_property<'a, P>(path: P) -> Result<Option<Bytes>, Status>
where
P: AsRef<[&'a str]>,
{
let serialized_path = utils::serialize_property_path(path);
let mut return_data: *mut u8 = null_mut();
let mut return_size: usize = 0;
Expand Down Expand Up @@ -451,7 +454,10 @@ extern "C" {
) -> Status;
}

pub fn set_property(path: Vec<&str>, value: Option<&[u8]>) -> Result<(), Status> {
pub fn set_property<'a, P>(path: P, value: Option<&[u8]>) -> Result<(), Status>
where
P: AsRef<[&'a str]>,
{
let serialized_path = utils::serialize_property_path(path);
unsafe {
match proxy_set_property(
Expand Down Expand Up @@ -1208,16 +1214,21 @@ mod utils {
use crate::types::Bytes;
use std::convert::TryFrom;

pub(super) fn serialize_property_path(path: Vec<&str>) -> Bytes {
pub(super) fn serialize_property_path<'a, P>(path: P) -> Bytes
where
P: AsRef<[&'a str]>,
{
let path = path.as_ref();

if path.is_empty() {
return Vec::new();
}
let mut size: usize = 0;
for part in &path {
for &part in path {
size += part.len() + 1;
}
let mut bytes: Bytes = Vec::with_capacity(size);
for part in &path {
for &part in path {
bytes.extend_from_slice(part.as_bytes());
bytes.push(0);
}
Expand Down