1use std::convert::Infallible;
2
3use crate::{ABIRequest, ABIResponse};
4use crate::abi::{LeakBuffer, OriginType};
5
6impl ABIRequest<'_> for Vec<u8> {
9 type DecodeError = Infallible;
10
11 fn try_from_bytes(buf: &'_ [u8]) -> Result<Self, Self::DecodeError>
12 where
13 Self: Sized,
14 {
15 Ok(buf.to_owned())
16 }
17}
18
19
20impl<'a> ABIRequest<'a> for &'a [u8] {
21 type DecodeError = Infallible;
22
23 fn try_from_bytes(buf: &'a [u8]) -> Result<Self, Self::DecodeError>
24 where
25 Self: Sized,
26 {
27 Ok(buf)
28 }
29}
30
31impl<'a> ABIRequest<'a> for &'a str {
32 type DecodeError = Infallible;
33
34 fn try_from_bytes(buf: &'a [u8]) -> Result<Self, Self::DecodeError>
35 where
36 Self: Sized,
37 {
38 Ok(unsafe { std::str::from_utf8_unchecked(buf) })
39 }
40}
41
42
43impl ABIResponse for Vec<u8> {
46 type EncodeError = Infallible;
47 const ORIGIN_TYPE_FOR_FREE: OriginType = OriginType::Vec;
48
49 fn try_into_buffer(self) -> Result<LeakBuffer, Self::EncodeError> {
50 Ok(LeakBuffer::from_vec(self))
51 }
52}
53
54impl ABIResponse for String {
55 type EncodeError = Infallible;
56 const ORIGIN_TYPE_FOR_FREE: OriginType = OriginType::Vec;
57
58 fn try_into_buffer(self) -> Result<LeakBuffer, Self::EncodeError> {
59 Ok(LeakBuffer::from_vec(self.into_bytes()))
60 }
61}