Skip to main content

ohos_web_binding/protocol/common/
mod.rs

1use std::ffi::c_char;
2
3use ohos_web_sys::{OH_ArkWeb_ReleaseByteArray, OH_ArkWeb_ReleaseString};
4
5/// Response Charset
6pub struct CommonString {
7    pub(crate) raw: *mut c_char,
8}
9
10impl Drop for CommonString {
11    fn drop(&mut self) {
12        unsafe {
13            OH_ArkWeb_ReleaseString(self.raw);
14        }
15    }
16}
17
18impl From<CommonString> for String {
19    fn from(value: CommonString) -> Self {
20        unsafe {
21            let s = std::ffi::CStr::from_ptr(value.raw);
22            s.to_string_lossy().to_string()
23        }
24    }
25}
26
27/// Common Bytes
28pub struct CommonBytes {
29    pub(crate) raw: *mut u8,
30}
31
32impl Drop for CommonBytes {
33    fn drop(&mut self) {
34        unsafe {
35            OH_ArkWeb_ReleaseByteArray(self.raw);
36        }
37    }
38}
39
40// Define response related types
41/// Response Charset
42pub type ResponseCharset = CommonString;
43/// Response Header Key
44pub type ResponseHeaderKey = CommonString;
45/// Response Header Value
46pub type ResponseHeaderValue = CommonString;
47/// Response Mime Type
48pub type ResponseMimeType = CommonString;
49/// Response Status Text
50pub type ResponseStatusText = CommonString;
51/// Response Url
52pub type Url = CommonString;
53/// Response Method
54pub type Method = CommonString;
55/// Response Referrer
56pub type Referrer = CommonString;