• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mattwparas / steel / 18461079395

13 Oct 2025 09:20AM UTC coverage: 42.731% (-0.9%) from 43.668%
18461079395

Pull #536

github

web-flow
Merge 6f55a8b56 into e378cba22
Pull Request #536: Initial proposal for no_std support

63 of 755 new or added lines in 38 files covered. (8.34%)

73 existing lines in 15 files now uncovered.

12324 of 28841 relevant lines covered (42.73%)

3215759.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/steel-webrequests/src/lib.rs
1
use steel::rvals::Custom;
2
use steel::{
3
    declare_module,
4
    steel_vm::ffi::{FFIModule, RegisterFFIFn},
5
};
6

7
use ureq::Request;
8

9
declare_module!(create_module);
10

11
fn create_module() -> FFIModule {
×
12
    let mut module = FFIModule::new("steel/web/blocking/requests".to_string());
×
13

14
    module
×
15
        .register_fn("client/new", Client::new)
×
16
        .register_fn("client/get", Client::get)
×
17
        .register_fn("client/post", Client::post)
×
18
        .register_fn("client/put", Client::put)
×
19
        .register_fn("client/patch", Client::patch)
×
20
        .register_fn("client/delete", Client::delete)
×
21
        .register_fn("client/head", Client::head)
×
22
        .register_fn("get", get)
×
23
        .register_fn("post", post)
×
24
        .register_fn("put", put)
×
25
        .register_fn("delete", delete)
×
26
        .register_fn("patch", patch)
×
27
        .register_fn("head", head)
×
28
        .register_fn("set-header!", BlockingRequest::set)
×
29
        .register_fn("set-query-parameter!", BlockingRequest::query)
×
30
        .register_fn("set-timeout/ms!", BlockingRequest::timeout_ms)
×
31
        .register_fn(
32
            "call",
33
            |request: &mut BlockingRequest| -> Result<SteelResponse, BlockingError> {
×
34
                Request::call(std::mem::take(&mut request.0).unwrap())
×
35
                    .map(|x| x.into())
×
NEW
36
                    .map_err(|e| BlockingError::Ureq { _inner: e })
×
37
            },
38
        )
39
        .register_fn("call-with-json", BlockingRequest::call_with_json)
×
40
        .register_fn("response->text", SteelResponse::into_text);
×
41

42
    module
×
43
}
44

45
#[derive(Clone)]
46
struct BlockingRequest(Option<Request>);
47

48
#[derive(Clone)]
49
struct Client(ureq::Agent);
50

51
#[derive(Debug)]
52
enum BlockingError {
53
    Ureq { _inner: ureq::Error },
54
    ResponseAlreadyUsed,
55
}
56

57
impl Custom for BlockingRequest {}
58
impl Custom for BlockingError {}
59
impl Custom for Client {}
60

61
impl Client {
62
    fn new() -> Self {
×
63
        Self(ureq::agent())
×
64
    }
65

66
    fn get(&self, url: &str) -> BlockingRequest {
×
67
        BlockingRequest(Some(self.0.get(url)))
×
68
    }
69

70
    fn post(&self, url: &str) -> BlockingRequest {
×
71
        BlockingRequest(Some(self.0.post(url)))
×
72
    }
73

74
    fn put(&self, url: &str) -> BlockingRequest {
×
75
        BlockingRequest(Some(self.0.put(url)))
×
76
    }
77

78
    fn patch(&self, url: &str) -> BlockingRequest {
×
79
        BlockingRequest(Some(self.0.patch(url)))
×
80
    }
81

82
    fn delete(&self, url: &str) -> BlockingRequest {
×
83
        BlockingRequest(Some(self.0.delete(url)))
×
84
    }
85

86
    fn head(&self, url: &str) -> BlockingRequest {
×
87
        BlockingRequest(Some(self.0.head(url)))
×
88
    }
89
}
90

91
fn get(url: String) -> BlockingRequest {
×
92
    BlockingRequest(Some(ureq::get(&url)))
×
93
}
94

95
fn post(url: String) -> BlockingRequest {
×
96
    BlockingRequest(Some(ureq::post(&url)))
×
97
}
98

99
fn put(url: String) -> BlockingRequest {
×
100
    BlockingRequest(Some(ureq::put(&url)))
×
101
}
102

103
fn delete(url: String) -> BlockingRequest {
×
104
    BlockingRequest(Some(ureq::delete(&url)))
×
105
}
106

107
fn patch(url: String) -> BlockingRequest {
×
108
    BlockingRequest(Some(ureq::patch(&url)))
×
109
}
110

111
fn head(url: String) -> BlockingRequest {
×
112
    BlockingRequest(Some(ureq::head(&url)))
×
113
}
114

115
impl BlockingRequest {
116
    fn query(&mut self, parameter: String, value: String) {
×
117
        self.0 = Some(self.0.take().unwrap().query(&parameter, &value));
×
118
    }
119

120
    fn set(&mut self, header: String, value: String) {
×
121
        self.0 = Some(self.0.take().unwrap().set(&header, &value));
×
122
    }
123

124
    // TODO: Add FFI conversion form u64 as well
125
    fn timeout_ms(&mut self, time_in_ms: usize) {
×
126
        self.0 = Some(
×
127
            self.0
×
128
                .take()
×
129
                .unwrap()
×
130
                .timeout(std::time::Duration::from_millis(time_in_ms as u64)),
×
131
        );
132
    }
133

134
    fn call_with_json(&mut self, json: String) -> Result<SteelResponse, BlockingError> {
×
135
        Request::send_json(self.0.clone().unwrap(), json)
×
136
            .map(|x| x.into())
×
NEW
137
            .map_err(|e| BlockingError::Ureq { _inner: e })
×
138
    }
139
}
140

141
struct SteelResponse {
142
    response: Option<ureq::Response>,
143
}
144

145
impl SteelResponse {
146
    fn into_text(&mut self) -> Result<String, BlockingError> {
×
147
        let resp = self.response.take();
×
148

149
        if let Some(resp) = resp {
×
150
            resp.into_string()
NEW
151
                .map_err(|x| BlockingError::Ureq { _inner: x.into() })
×
152
        } else {
153
            Err(BlockingError::ResponseAlreadyUsed)
×
154
        }
155
    }
156
}
157

158
impl From<ureq::Response> for SteelResponse {
159
    fn from(value: ureq::Response) -> Self {
×
160
        SteelResponse {
161
            response: Some(value),
×
162
        }
163
    }
164
}
165

166
impl Custom for SteelResponse {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc