Skip to content

Commit 4814505

Browse files
Reflected changes to actix-web module
Signed-off-by: Francesco Guardiani <[email protected]>
1 parent 534cf01 commit 4814505

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

cloudevents-sdk-actix-web/src/server_request.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use actix_web::web::{Bytes, BytesMut};
44
use actix_web::{web, HttpMessage, HttpRequest};
55
use cloudevents::event::SpecVersion;
66
use cloudevents::message::{
7-
BinaryDeserializer, BinarySerializer, Encoding, Error, MessageAttributeValue,
8-
MessageDeserializer, StructuredDeserializer, StructuredSerializer,
7+
BinaryDeserializer, BinarySerializer, Encoding, MessageAttributeValue,
8+
MessageDeserializer, StructuredDeserializer, StructuredSerializer, Result
99
};
1010
use cloudevents::{message, Event};
1111
use futures::StreamExt;
@@ -27,7 +27,7 @@ impl<'a> BinaryDeserializer for HttpRequestDeserializer<'a> {
2727
fn deserialize_binary<R: Sized, V: BinarySerializer<R>>(
2828
self,
2929
mut visitor: V,
30-
) -> Result<R, Error> {
30+
) -> Result<R> {
3131
if self.encoding() != Encoding::BINARY {
3232
return Err(message::Error::WrongEncoding {});
3333
}
@@ -36,7 +36,7 @@ impl<'a> BinaryDeserializer for HttpRequestDeserializer<'a> {
3636
unwrap_optional_header!(self.req.headers(), headers::SPEC_VERSION_HEADER).unwrap()?,
3737
)?;
3838

39-
visitor.set_spec_version(spec_version.clone())?;
39+
visitor = visitor.set_spec_version(spec_version.clone())?;
4040

4141
let attributes = cloudevents::event::spec_version::ATTRIBUTE_NAMES
4242
.get(&spec_version)
@@ -50,20 +50,20 @@ impl<'a> BinaryDeserializer for HttpRequestDeserializer<'a> {
5050
let name = &hn.as_str()["ce-".len()..];
5151

5252
if attributes.contains(&name) {
53-
visitor.set_attribute(
53+
visitor = visitor.set_attribute(
5454
name,
5555
MessageAttributeValue::String(String::from(header_value_to_str!(hv)?)),
5656
)?
5757
} else {
58-
visitor.set_extension(
58+
visitor = visitor.set_extension(
5959
name,
6060
MessageAttributeValue::String(String::from(header_value_to_str!(hv)?)),
6161
)?
6262
}
6363
}
6464

6565
if let Some(hv) = self.req.headers().get("content-type") {
66-
visitor.set_attribute(
66+
visitor = visitor.set_attribute(
6767
"datacontenttype",
6868
MessageAttributeValue::String(String::from(header_value_to_str!(hv)?)),
6969
)?
@@ -81,7 +81,7 @@ impl<'a> StructuredDeserializer for HttpRequestDeserializer<'a> {
8181
fn deserialize_structured<R: Sized, V: StructuredSerializer<R>>(
8282
self,
8383
visitor: V,
84-
) -> Result<R, Error> {
84+
) -> Result<R> {
8585
if self.encoding() != Encoding::STRUCTURED {
8686
return Err(message::Error::WrongEncoding {});
8787
}
@@ -110,7 +110,7 @@ impl<'a> MessageDeserializer for HttpRequestDeserializer<'a> {
110110
pub async fn request_to_event(
111111
req: &HttpRequest,
112112
mut payload: web::Payload,
113-
) -> Result<Event, actix_web::error::Error> {
113+
) -> std::result::Result<Event, actix_web::error::Error> {
114114
let mut bytes = BytesMut::new();
115115
while let Some(item) = payload.next().await {
116116
bytes.extend_from_slice(&item?);

cloudevents-sdk-actix-web/src/server_response.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use actix_web::http::{HeaderName, HeaderValue};
44
use actix_web::HttpResponse;
55
use cloudevents::event::SpecVersion;
66
use cloudevents::message::{
7-
BinaryDeserializer, BinarySerializer, Error, MessageAttributeValue, SerializationResult,
7+
BinaryDeserializer, BinarySerializer, MessageAttributeValue, Result,
88
StructuredSerializer,
99
};
1010
use cloudevents::Event;
@@ -21,41 +21,41 @@ impl HttpResponseSerializer {
2121
}
2222

2323
impl BinarySerializer<HttpResponse> for HttpResponseSerializer {
24-
fn set_spec_version(&mut self, spec_version: SpecVersion) -> SerializationResult {
24+
fn set_spec_version(mut self, spec_version: SpecVersion) -> Result<Self> {
2525
self.builder.set_header(
2626
headers::SPEC_VERSION_HEADER.clone(),
2727
str_to_header_value!(spec_version.as_str())?,
2828
);
29-
SerializationResult::Ok(())
29+
Ok(self)
3030
}
3131

32-
fn set_attribute(&mut self, name: &str, value: MessageAttributeValue) -> SerializationResult {
32+
fn set_attribute(mut self, name: &str, value: MessageAttributeValue) -> Result<Self> {
3333
self.builder.set_header(
3434
headers::ATTRIBUTES_TO_HEADERS.get(name).unwrap().clone(),
3535
str_to_header_value!(value.to_string().as_str())?,
3636
);
37-
SerializationResult::Ok(())
37+
Ok(self)
3838
}
3939

40-
fn set_extension(&mut self, name: &str, value: MessageAttributeValue) -> SerializationResult {
40+
fn set_extension(mut self, name: &str, value: MessageAttributeValue) -> Result<Self> {
4141
self.builder.set_header(
4242
attribute_name_to_header!(name)?,
4343
str_to_header_value!(value.to_string().as_str())?,
4444
);
45-
SerializationResult::Ok(())
45+
Ok(self)
4646
}
4747

48-
fn end_with_data(mut self, bytes: Vec<u8>) -> Result<HttpResponse, Error> {
48+
fn end_with_data(mut self, bytes: Vec<u8>) -> Result<HttpResponse> {
4949
Ok(self.builder.body(bytes))
5050
}
5151

52-
fn end(mut self) -> Result<HttpResponse, Error> {
52+
fn end(mut self) -> Result<HttpResponse> {
5353
Ok(self.builder.finish())
5454
}
5555
}
5656

5757
impl StructuredSerializer<HttpResponse> for HttpResponseSerializer {
58-
fn set_structured_event(mut self, bytes: Vec<u8>) -> Result<HttpResponse, Error> {
58+
fn set_structured_event(mut self, bytes: Vec<u8>) -> Result<HttpResponse> {
5959
Ok(self
6060
.builder
6161
.set_header(
@@ -70,7 +70,7 @@ impl StructuredSerializer<HttpResponse> for HttpResponseSerializer {
7070
pub async fn event_to_response(
7171
event: Event,
7272
response: HttpResponseBuilder,
73-
) -> Result<HttpResponse, actix_web::error::Error> {
73+
) -> std::result::Result<HttpResponse, actix_web::error::Error> {
7474
BinaryDeserializer::deserialize_binary(event, HttpResponseSerializer::new(response))
7575
.map_err(actix_web::error::ErrorBadRequest)
7676
}

src/message/deserializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{BinarySerializer, Encoding, Error, StructuredSerializer, Result};
1+
use super::{BinarySerializer, Encoding, StructuredSerializer, Result};
22
use crate::Event;
33

44
pub trait StructuredDeserializer

0 commit comments

Comments
 (0)