Skip to content

Commit

Permalink
Change SRData::from to take &[u8] rather than &Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
irh committed Aug 4, 2023
1 parent 03d5b7b commit 1506a08
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src-rs/types/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl AsRef<[u8]> for SRData {
}
}

impl From<&Vec<u8>> for SRData {
fn from(value: &Vec<u8>) -> Self {
impl From<&[u8]> for SRData {
fn from(value: &[u8]) -> Self {
unsafe { swift::data_from_bytes(value.as_ptr(), value.len() as Int) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ swift!(fn echo_data(data: &SRData) -> SRData);
fn test_data() {
test_with_leaks!(|| {
let str: &str = "hello";
let bytes = &str.as_bytes().to_vec();
let bytes = str.as_bytes();
for _ in 0..10_000 {
let data = unsafe { echo_data(&bytes.into()) };
assert_eq!(data.as_slice(), bytes);
Expand Down

0 comments on commit 1506a08

Please sign in to comment.