From 2bce7b97d3fe785648dc1e844b3ef4a51ff6b946 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Mon, 28 Oct 2024 18:02:16 -0400 Subject: [PATCH] Stop using "our" Bytes type. It's a simple alias to Vec, so it doesn't provide any value, and it conflicts with a popular Bytes type from the bytes crate. This is a non-breaking change, since we retain the public alias. Signed-off-by: Piotr Sikora --- src/hostcalls.rs | 29 ++++++++++++------------ src/traits.rs | 58 ++++++++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/hostcalls.rs b/src/hostcalls.rs index 15687888..a087a025 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 { @@ -393,7 +393,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; @@ -457,7 +457,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; @@ -568,7 +568,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 { @@ -1029,7 +1029,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 { @@ -1139,10 +1139,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(); } @@ -1150,7 +1149,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); @@ -1159,12 +1158,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()); @@ -1179,12 +1178,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()); @@ -1223,7 +1222,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)> { let mut map = Vec::new(); if bytes.is_empty() { return map; diff --git a/src/traits.rs b/src/traits.rs index bd54bcbe..64e9b758 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() } @@ -201,7 +201,7 @@ pub trait Context { &self, function_name: &str, arguments: Option<&[u8]>, - ) -> Result, Status> { + ) -> Result>, Status> { hostcalls::call_foreign_function(function_name, arguments) } @@ -219,7 +219,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() } @@ -227,7 +227,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() } @@ -263,7 +263,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() } @@ -285,7 +285,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() } @@ -315,7 +315,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() } @@ -331,7 +331,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() } @@ -355,7 +355,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() } @@ -371,7 +371,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() } @@ -387,7 +387,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() } @@ -423,7 +423,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() } @@ -439,7 +439,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() } @@ -463,7 +463,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() } @@ -479,7 +479,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() } @@ -495,7 +495,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() }