diff --git a/src/hostcalls.rs b/src/hostcalls.rs index 8dbc335..f98a8eb 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -85,7 +85,7 @@ pub fn get_buffer( buffer_type: BufferType, start: usize, max_size: usize, -) -> Result, Status> { +) -> Result>, Status> { let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; unsafe { @@ -163,7 +163,7 @@ pub fn get_map(map_type: MapType) -> Result, Status> { } } -pub fn get_map_bytes(map_type: MapType) -> Result, Status> { +pub fn get_map_bytes(map_type: MapType) -> Result)>, Status> { unsafe { let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; @@ -250,7 +250,7 @@ pub fn get_map_value(map_type: MapType, key: &str) -> Result, Sta } } -pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result, Status> { +pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result>, Status> { let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; unsafe { @@ -402,7 +402,7 @@ extern "C" { ) -> Status; } -pub fn get_property(path: Vec<&str>) -> Result, Status> { +pub fn get_property(path: Vec<&str>) -> Result>, Status> { let serialized_path = utils::serialize_property_path(path); let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; @@ -466,7 +466,7 @@ extern "C" { ) -> Status; } -pub fn get_shared_data(key: &str) -> Result<(Option, Option), Status> { +pub fn get_shared_data(key: &str) -> Result<(Option>, Option), Status> { let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; let mut return_cas: u32 = 0; @@ -577,7 +577,7 @@ extern "C" { ) -> Status; } -pub fn dequeue_shared_queue(queue_id: u32) -> Result, Status> { +pub fn dequeue_shared_queue(queue_id: u32) -> Result>, Status> { let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; unsafe { @@ -1038,7 +1038,7 @@ extern "C" { pub fn call_foreign_function( function_name: &str, arguments: Option<&[u8]>, -) -> Result, Status> { +) -> Result>, Status> { let mut return_data: *mut u8 = null_mut(); let mut return_size: usize = 0; unsafe { @@ -1148,10 +1148,9 @@ pub fn increment_metric(metric_id: u32, offset: i64) -> Result<(), Status> { } 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(path: Vec<&str>) -> Vec { if path.is_empty() { return Vec::new(); } @@ -1159,7 +1158,7 @@ mod utils { for part in &path { size += part.len() + 1; } - let mut bytes: Bytes = Vec::with_capacity(size); + let mut bytes = Vec::with_capacity(size); for part in &path { bytes.extend_from_slice(part.as_bytes()); bytes.push(0); @@ -1168,12 +1167,12 @@ mod utils { bytes } - pub(super) fn serialize_map(map: Vec<(&str, &str)>) -> Bytes { + pub(super) fn serialize_map(map: Vec<(&str, &str)>) -> Vec { let mut size: usize = 4; for (name, value) in &map { size += name.len() + value.len() + 10; } - let mut bytes: Bytes = Vec::with_capacity(size); + let mut bytes = Vec::with_capacity(size); bytes.extend_from_slice(&map.len().to_le_bytes()); for (name, value) in &map { bytes.extend_from_slice(&name.len().to_le_bytes()); @@ -1188,12 +1187,12 @@ mod utils { bytes } - pub(super) fn serialize_map_bytes(map: Vec<(&str, &[u8])>) -> Bytes { + pub(super) fn serialize_map_bytes(map: Vec<(&str, &[u8])>) -> Vec { let mut size: usize = 4; for (name, value) in &map { size += name.len() + value.len() + 10; } - let mut bytes: Bytes = Vec::with_capacity(size); + let mut bytes = Vec::with_capacity(size); bytes.extend_from_slice(&map.len().to_le_bytes()); for (name, value) in &map { bytes.extend_from_slice(&name.len().to_le_bytes()); @@ -1232,7 +1231,7 @@ mod utils { map } - pub(super) fn deserialize_map_bytes(bytes: &[u8]) -> Vec<(String, Bytes)> { + pub(super) fn deserialize_map_bytes(bytes: &[u8]) -> Vec<(String, Vec)> { if bytes.is_empty() { return Vec::new(); } diff --git a/src/traits.rs b/src/traits.rs index 065e836..c603d27 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -21,7 +21,7 @@ pub trait Context { hostcalls::get_current_time().unwrap() } - fn get_property(&self, path: Vec<&str>) -> Option { + fn get_property(&self, path: Vec<&str>) -> Option> { hostcalls::get_property(path).unwrap() } @@ -29,7 +29,7 @@ pub trait Context { hostcalls::set_property(path, value).unwrap() } - fn get_shared_data(&self, key: &str) -> (Option, Option) { + fn get_shared_data(&self, key: &str) -> (Option>, Option) { hostcalls::get_shared_data(key).unwrap() } @@ -50,7 +50,7 @@ pub trait Context { hostcalls::resolve_shared_queue(vm_id, name).unwrap() } - fn dequeue_shared_queue(&self, queue_id: u32) -> Result, Status> { + fn dequeue_shared_queue(&self, queue_id: u32) -> Result>, Status> { hostcalls::dequeue_shared_queue(queue_id) } @@ -82,7 +82,7 @@ pub trait Context { hostcalls::get_map(MapType::HttpCallResponseHeaders).unwrap() } - fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Bytes)> { + fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::HttpCallResponseHeaders).unwrap() } @@ -90,11 +90,11 @@ pub trait Context { hostcalls::get_map_value(MapType::HttpCallResponseHeaders, name).unwrap() } - fn get_http_call_response_header_bytes(&self, name: &str) -> Option { + fn get_http_call_response_header_bytes(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::HttpCallResponseHeaders, name).unwrap() } - fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option { + fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::HttpCallResponseBody, start, max_size).unwrap() } @@ -102,7 +102,7 @@ pub trait Context { hostcalls::get_map(MapType::HttpCallResponseTrailers).unwrap() } - fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { + fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::HttpCallResponseTrailers).unwrap() } @@ -110,7 +110,7 @@ pub trait Context { hostcalls::get_map_value(MapType::HttpCallResponseTrailers, name).unwrap() } - fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option { + fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::HttpCallResponseTrailers, name).unwrap() } @@ -135,7 +135,7 @@ pub trait Context { fn on_grpc_call_response(&mut self, _token_id: u32, _status_code: u32, _response_size: usize) {} - fn get_grpc_call_response_body(&self, start: usize, max_size: usize) -> Option { + fn get_grpc_call_response_body(&self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap() } @@ -155,11 +155,11 @@ pub trait Context { fn on_grpc_stream_initial_metadata(&mut self, _token_id: u32, _num_elements: u32) {} - fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Bytes)> { + fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::GrpcReceiveInitialMetadata).unwrap() } - fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option { + fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::GrpcReceiveInitialMetadata, name).unwrap() } @@ -169,17 +169,17 @@ pub trait Context { fn on_grpc_stream_message(&mut self, _token_id: u32, _message_size: usize) {} - fn get_grpc_stream_message(&mut self, start: usize, max_size: usize) -> Option { + fn get_grpc_stream_message(&mut self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap() } fn on_grpc_stream_trailing_metadata(&mut self, _token_id: u32, _num_elements: u32) {} - fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Bytes)> { + fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::GrpcReceiveTrailingMetadata).unwrap() } - fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option { + fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::GrpcReceiveTrailingMetadata, name).unwrap() } @@ -203,7 +203,7 @@ pub trait Context { &self, function_name: &str, arguments: Option<&[u8]>, - ) -> Result, Status> { + ) -> Result>, Status> { hostcalls::call_foreign_function(function_name, arguments) } @@ -221,7 +221,7 @@ pub trait RootContext: Context { true } - fn get_vm_configuration(&self) -> Option { + fn get_vm_configuration(&self) -> Option> { hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap() } @@ -229,7 +229,7 @@ pub trait RootContext: Context { true } - fn get_plugin_configuration(&self) -> Option { + fn get_plugin_configuration(&self) -> Option> { hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap() } @@ -265,7 +265,7 @@ pub trait StreamContext: Context { Action::Continue } - fn get_downstream_data(&self, start: usize, max_size: usize) -> Option { + fn get_downstream_data(&self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::DownstreamData, start, max_size).unwrap() } @@ -287,7 +287,7 @@ pub trait StreamContext: Context { Action::Continue } - fn get_upstream_data(&self, start: usize, max_size: usize) -> Option { + fn get_upstream_data(&self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::UpstreamData, start, max_size).unwrap() } @@ -317,7 +317,7 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() } - fn get_http_request_headers_bytes(&self) -> Vec<(String, Bytes)> { + fn get_http_request_headers_bytes(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::HttpRequestHeaders).unwrap() } @@ -333,7 +333,7 @@ pub trait HttpContext: Context { hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() } - fn get_http_request_header_bytes(&self, name: &str) -> Option { + fn get_http_request_header_bytes(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::HttpRequestHeaders, name).unwrap() } @@ -361,7 +361,7 @@ pub trait HttpContext: Context { Action::Continue } - fn get_http_request_body(&self, start: usize, max_size: usize) -> Option { + fn get_http_request_body(&self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::HttpRequestBody, start, max_size).unwrap() } @@ -377,7 +377,7 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpRequestTrailers).unwrap() } - fn get_http_request_trailers_bytes(&self) -> Vec<(String, Bytes)> { + fn get_http_request_trailers_bytes(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::HttpRequestTrailers).unwrap() } @@ -393,7 +393,7 @@ pub trait HttpContext: Context { hostcalls::get_map_value(MapType::HttpRequestTrailers, name).unwrap() } - fn get_http_request_trailer_bytes(&self, name: &str) -> Option { + fn get_http_request_trailer_bytes(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::HttpRequestTrailers, name).unwrap() } @@ -433,7 +433,7 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpResponseHeaders).unwrap() } - fn get_http_response_headers_bytes(&self) -> Vec<(String, Bytes)> { + fn get_http_response_headers_bytes(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::HttpResponseHeaders).unwrap() } @@ -449,7 +449,7 @@ pub trait HttpContext: Context { hostcalls::get_map_value(MapType::HttpResponseHeaders, name).unwrap() } - fn get_http_response_header_bytes(&self, name: &str) -> Option { + fn get_http_response_header_bytes(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::HttpResponseHeaders, name).unwrap() } @@ -477,7 +477,7 @@ pub trait HttpContext: Context { Action::Continue } - fn get_http_response_body(&self, start: usize, max_size: usize) -> Option { + fn get_http_response_body(&self, start: usize, max_size: usize) -> Option> { hostcalls::get_buffer(BufferType::HttpResponseBody, start, max_size).unwrap() } @@ -493,7 +493,7 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpResponseTrailers).unwrap() } - fn get_http_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { + fn get_http_response_trailers_bytes(&self) -> Vec<(String, Vec)> { hostcalls::get_map_bytes(MapType::HttpResponseTrailers).unwrap() } @@ -509,7 +509,7 @@ pub trait HttpContext: Context { hostcalls::get_map_value(MapType::HttpResponseTrailers, name).unwrap() } - fn get_http_response_trailer_bytes(&self, name: &str) -> Option { + fn get_http_response_trailer_bytes(&self, name: &str) -> Option> { hostcalls::get_map_value_bytes(MapType::HttpResponseTrailers, name).unwrap() }