Skip to content

Commit 4473a16

Browse files
Copilotjsturtevant
andcommitted
Fix README.md host function calling examples to match current API
Co-authored-by: jsturtevant <[email protected]>
1 parent 93e5e20 commit 4473a16

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ It is followed by an example of a simple guest application using the Hyperlight
3333
### Host
3434

3535
```rust
36-
use std::{thread, sync::{Arc, Mutex}};
36+
use std::thread;
3737

38-
use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType};
39-
use hyperlight_host::{UninitializedSandbox, MultiUseSandbox, func::HostFunction0, sandbox_state::transition::Noop, sandbox_state::sandbox::EvolvableSandbox};
38+
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
39+
use hyperlight_host::sandbox_state::transition::Noop;
40+
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
4041

4142
fn main() -> hyperlight_host::Result<()> {
4243
// Create an uninitialized sandbox with a guest binary
@@ -59,12 +60,10 @@ fn main() -> hyperlight_host::Result<()> {
5960
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
6061
// in order to call a function it first must be defined in the guest and exposed so that
6162
// the host can call it
62-
let result: i32 = multi_use_sandbox.call_guest_function_by_name(
63+
multi_use_sandbox.call_guest_function_by_name::<i32>(
6364
"PrintOutput",
6465
message,
65-
);
66-
67-
assert!(result.is_ok());
66+
)?;
6867

6968
Ok(())
7069
}
@@ -84,7 +83,7 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{
8483
ParameterType, ParameterValue, ReturnType,
8584
};
8685
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
87-
use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result_from_int;
86+
use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
8887

8988
use hyperlight_guest::error::{HyperlightGuestError, Result};
9089
use hyperlight_guest_bin::guest_function::definition::GuestFunctionDefinition;
@@ -93,13 +92,12 @@ use hyperlight_guest_bin::host_comm::{call_host_function, call_host_function_wit
9392

9493
fn print_output(function_call: &FunctionCall) -> Result<Vec<u8>> {
9594
if let ParameterValue::String(message) = function_call.parameters.clone().unwrap()[0].clone() {
96-
call_host_function(
95+
let result = call_host_function::<i32>(
9796
"HostPrint",
9897
Some(Vec::from(&[ParameterValue::String(message.to_string())])),
9998
ReturnType::Int,
10099
)?;
101-
let result = get_host_value_return_as_int()?;
102-
Ok(get_flatbuffer_result_from_int(result))
100+
Ok(get_flatbuffer_result(result))
103101
} else {
104102
Err(HyperlightGuestError::new(
105103
ErrorCode::GuestFunctionParameterTypeMismatch,

0 commit comments

Comments
 (0)