Struct Request

Source
pub struct Request<T>
where T: Serialize,
{ /* private fields */ }

Implementations§

Source§

impl Request<()>

Source

pub fn new() -> Request<()>

Examples found in repository?
examples/demo.rs (line 80)
70fn debug_request_parse_full_http2() {
71    let http2: Vec<u8> = vec![
72        80, 82, 73, 32, 42, 32, 72, 84, 84, 80, 47, 50, 46, 48, 13, 10, 13, 10, 83, 77, 13, 10, 13,
73        10, 0, 0, 18, 4, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 100, 0, 4, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
74        0, 4, 8, 0, 0, 0, 0, 0, 1, 255, 0, 1, 0, 0, 55, 1, 5, 0, 0, 0, 1, 131, 132, 134, 65, 143,
75        11, 226, 92, 46, 60, 184, 93, 125, 112, 178, 205, 199, 128, 240, 63, 122, 136, 37, 182, 80,
76        195, 171, 186, 210, 224, 83, 3, 42, 47, 42, 64, 136, 37, 168, 73, 233, 91, 169, 125, 127,
77        137, 37, 168, 73, 233, 91, 184, 232, 180, 191, 0, 0, 25, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78        0, 0, 1, 83, 69, 84, 84, 73, 78, 71, 83, 32, 101, 120, 112, 101, 99, 116, 101, 100,
79    ];
80    let mut req = Request::new();
81    let _size = req.parse(&http2).unwrap();
82    println!("req = {:?}", req);
83}
84
85// fn debug_request_parse_http2() {
86//     let mut decode = Decoder::new();
87//     let _http2 = vec![
88//         0x82, 0x86, 0x84, 0x41, 0x8c, 0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90,
89//         0xf4, 0xff,
90//     ];
91//     let http2 = hexstr_to_vec("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ");
92
93//     let mut buf = BinaryMut::from(http2);
94
95//     let _result = decode.decode_with_cb(&mut buf, |n, v| {
96//         println!("n = {:?}, v = {:?}", n, v);
97//     });
98//     // println!("result = {:?}", result);
99//     // let http2 = vec![
100//     //     0x82, 0x86, 0x84, 0xbe, 0x58, 0x08, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65,
101//     // ];
102//     // let http2 = hexstr_to_vec("8286 84be 5808 6e6f 2d63 6163 6865");
103
104//     // let mut buf = BinaryMut::from(http2);
105//     // let result = decode.decode_with_cb(&mut buf, |n, v| {
106//     //     println!("n = {:?}, v = {:?}", n, v);
107//     // });
108//     // println!("result = {:?}", result);
109
110//     // {
111//     //     //         8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 | ....@.%.I.[.}..%
112//     //     //          a849 e95b b8e8 b4bf
113//     //     let http2 = vec![
114//     //         0x82, 0x87, 0x85, 0xbf, 0x40, 0x88, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xa9, 0x7d, 0x7f,
115//     //         0x89, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xb8, 0xe8, 0xb4, 0xbf,
116//     //     ];
117//     //     let http2 = hexstr_to_vec(
118//     //         "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65",
119//     //     );
120
121//     //     let mut buf = BinaryMut::from(http2);
122
123//     //     let result = decode.decode_with_cb(&mut buf, |n, v| {
124//     //         println!("n = {:?}, v = {:?}", n, v);
125//     //     });
126//     //     println!("result = {:?}", result);
127//     // }
128// }
129
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
178
179fn main() {
180    let mut req = crate::Request::new();
181    let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
182    assert!(ret.err().unwrap().is_partial());
183
184    let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
185    let ret = req.parse(buf).unwrap();
186
187    assert!(ret == buf.len());
188    assert!(req.is_complete());
189
190    debug_request_parse();
191    // let mut binmut = BinaryMut::new();
192    // "aaa".serialize1(&mut binmut);
193
194    // let bin = Binary::new();
195    // let p = Pay::Data(bin);
196    // println!("bbb = {:?}", p);
197    // debug_request_parse_full_http2();
198    // debug_request_parse_http2();
199
200    //  let req = request::Builder::new()
201    //      .method("POST")
202    //      .body(())
203    //      .unwrap();
204
205    // debug_request_parse();
206    // let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
207    // let mut b = Binary::from(v);
208    // {
209    //     b.get_next();
210    //     let c = b.clone_slice();
211    //     drop(c);
212    //     b.get_next();
213    //     let d = b.clone_slice();
214    //     drop(d);
215    // }
216    // drop(b);
217    println!("finish");
218    // let len = v.len();
219    // let raw = Box::into_raw(v) as *mut u8;
220
221    // // Layout::from_size_align(cap, 1);
222
223    // let value = unsafe { Vec::from_raw_parts(raw, len, len) };
224    // println!("value = {:?}", value);
225
226    if true {
227        return;
228    }
229
230    // let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
231    // // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
232    // // println!("result = {:?}", request);
233    // // println!("is_partial = {}", request.is_partial());
234
235    // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
236    // println!("result = {:?}", request);
237    // println!("is_partial = {}", request.is_partial());
238    // println!("body len = {}", request.get_body_len());
239
240    let url: Result<Url, webparse::WebError> =
241        Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
242    println!("value = {:?}", url);
243    println!("value = {}", url.ok().unwrap());
244
245    let url = Url::try_from("/path?qqq=222");
246    println!("value = {:?}", url);
247    println!("value = {}", url.ok().unwrap());
248
249    println!("decode = {:?}", Url::url_decode("%48%211111"));
250    println!("decode = {:?}", Url::url_decode("%48%21111%1"));
251    println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
252    let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
253    println!("value = {}", value);
254
255    // // let value = url::Url::parse("/path");
256    // let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
257    // println!("result = {:?}", request);
258    // println!("is_partial = {}", request.is_partial());
259    // println!("body len = {}", request.get_body_len());
260    // println!("host len = {:?}", request.get_host());
261    // println!("host len = {:?}", request.get_connect_url());
262
263    // let mut buffer = Buffer::new();
264    // request.serialize(&mut buffer).expect("ok");
265    // println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
266
267    // println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
268
269    // let mut req = Request::builder();
270    // assert_eq!(req.url_ref().unwrap(), "/" );
271    // req = req.url("https://www.rust-lang.org/");
272    // assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
273
274    // let mut req = Request::builder().version(Version::Http2).method("GET")
275    //     .header("Accept", "text/html")
276    //     .header("X-Custom-Foo", "bar");
277    // {
278    //     let headers = req.headers_mut().unwrap();
279    //     headers["AAAA"] = HeaderValue::Stand("ok");
280    //     let xx = &headers["Accept"];
281    //     let aaa = &headers["AAAA"];
282    //     println!("xxx = {:?}", xx);
283    //     println!("aaa = {:?}", aaa);
284
285    //     for value in headers.iter() {
286    //         println!("____={:?}", value.0);
287    //         println!("____={:?}", value.1);
288    //     }
289    //     assert_eq!( &headers["Accept"], "text/html" );
290    //     assert_eq!( &headers["X-Custom-Foo"], "bar" );
291    // }
292
293    let req = Request::builder()
294        .version(Version::Http2)
295        .method("GET")
296        .url("/")
297        .header(":scheme", "http")
298        .header(":authority", "www.example.com");
299    {
300        // let headers = req.headers_mut().unwrap();
301        // headers["AAAA"] = HeaderValue::Stand("ok");
302        // let xx = &headers["Accept"];
303        // let aaa = &headers["AAAA"];
304        // println!("xxx = {:?}", xx);
305        // println!("aaa = {:?}", aaa);
306
307        // for value in headers.iter() {
308        //     println!("____={:?}", value.0);
309        //     println!("____={:?}", value.1);
310        // }
311        // assert_eq!( &headers["Accept"], "text/html" );
312        // assert_eq!( &headers["X-Custom-Foo"], "bar" );
313    }
314
315    let _rrr = req.body(()).unwrap();
316
317    // let data = rrr.http2data().unwrap();
318
319    // println!("req.httpdata() = {:?}", hex_debug_print(&data));
320
321    // let mut decode = Decoder::new();
322    // let mut buf = BinaryMut::from(data);
323    // let result = decode.decode_with_cb(&mut buf, |n, v| {
324    //     println!("n = {:?}, v = {}", n, v);
325    // });
326
327    // let mut index = Arc::new(HeaderIndex::new());
328    // Arc::get_mut(&mut index).map(|v| {
329    //     v.add_header(
330    //         HeaderName::from_static("aaa"),
331    //         HeaderValue::from_static("aa"),
332    //     );
333    // });
334
335    // let xx = Arc::get_mut(&mut index);
336    // println!("========={:?}", xx);
337    // let xx111 = Arc::get_mut(&mut index);
338    // println!("========={:?}", xx111);
339    // // rrr.extensions_mut().insert(index);
340    // // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
341    // // println!("========={:?}", new);
342
343    // // if true {
344    // //     return;
345    // // }
346
347    // let u = url::Builder::new()
348    //     .scheme("https")
349    //     .domain("www.baidu.com")
350    //     .build()
351    //     .unwrap();
352    // println!("u = {}", u);
353
354    // let response = Response::builder()
355    //     .header("Accept", "text/html")
356    //     .header("X-Custom-Foo", "bar")
357    //     .body("my is web")
358    //     .unwrap();
359
360    // println!(
361    //     "ssssssssssss {}",
362    //     String::from_utf8_lossy(&response.httpdata().unwrap())
363    // );
364
365    let mut xx = HashMap::<(u32, u8), u8>::new();
366    xx.insert((48, 5), 6);
367
368    // xx.get(&b"xx");
369
370    println!("aaa {:?}", xx.get(&(48, 5)));
371    // let response = url::Builder::
372}
Source

pub fn new_by_parts(parts: Parts) -> Request<()>

Source

pub fn builder() -> Builder

Examples found in repository?
examples/demo.rs (line 293)
179fn main() {
180    let mut req = crate::Request::new();
181    let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
182    assert!(ret.err().unwrap().is_partial());
183
184    let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
185    let ret = req.parse(buf).unwrap();
186
187    assert!(ret == buf.len());
188    assert!(req.is_complete());
189
190    debug_request_parse();
191    // let mut binmut = BinaryMut::new();
192    // "aaa".serialize1(&mut binmut);
193
194    // let bin = Binary::new();
195    // let p = Pay::Data(bin);
196    // println!("bbb = {:?}", p);
197    // debug_request_parse_full_http2();
198    // debug_request_parse_http2();
199
200    //  let req = request::Builder::new()
201    //      .method("POST")
202    //      .body(())
203    //      .unwrap();
204
205    // debug_request_parse();
206    // let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
207    // let mut b = Binary::from(v);
208    // {
209    //     b.get_next();
210    //     let c = b.clone_slice();
211    //     drop(c);
212    //     b.get_next();
213    //     let d = b.clone_slice();
214    //     drop(d);
215    // }
216    // drop(b);
217    println!("finish");
218    // let len = v.len();
219    // let raw = Box::into_raw(v) as *mut u8;
220
221    // // Layout::from_size_align(cap, 1);
222
223    // let value = unsafe { Vec::from_raw_parts(raw, len, len) };
224    // println!("value = {:?}", value);
225
226    if true {
227        return;
228    }
229
230    // let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
231    // // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
232    // // println!("result = {:?}", request);
233    // // println!("is_partial = {}", request.is_partial());
234
235    // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
236    // println!("result = {:?}", request);
237    // println!("is_partial = {}", request.is_partial());
238    // println!("body len = {}", request.get_body_len());
239
240    let url: Result<Url, webparse::WebError> =
241        Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
242    println!("value = {:?}", url);
243    println!("value = {}", url.ok().unwrap());
244
245    let url = Url::try_from("/path?qqq=222");
246    println!("value = {:?}", url);
247    println!("value = {}", url.ok().unwrap());
248
249    println!("decode = {:?}", Url::url_decode("%48%211111"));
250    println!("decode = {:?}", Url::url_decode("%48%21111%1"));
251    println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
252    let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
253    println!("value = {}", value);
254
255    // // let value = url::Url::parse("/path");
256    // let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
257    // println!("result = {:?}", request);
258    // println!("is_partial = {}", request.is_partial());
259    // println!("body len = {}", request.get_body_len());
260    // println!("host len = {:?}", request.get_host());
261    // println!("host len = {:?}", request.get_connect_url());
262
263    // let mut buffer = Buffer::new();
264    // request.serialize(&mut buffer).expect("ok");
265    // println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
266
267    // println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
268
269    // let mut req = Request::builder();
270    // assert_eq!(req.url_ref().unwrap(), "/" );
271    // req = req.url("https://www.rust-lang.org/");
272    // assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
273
274    // let mut req = Request::builder().version(Version::Http2).method("GET")
275    //     .header("Accept", "text/html")
276    //     .header("X-Custom-Foo", "bar");
277    // {
278    //     let headers = req.headers_mut().unwrap();
279    //     headers["AAAA"] = HeaderValue::Stand("ok");
280    //     let xx = &headers["Accept"];
281    //     let aaa = &headers["AAAA"];
282    //     println!("xxx = {:?}", xx);
283    //     println!("aaa = {:?}", aaa);
284
285    //     for value in headers.iter() {
286    //         println!("____={:?}", value.0);
287    //         println!("____={:?}", value.1);
288    //     }
289    //     assert_eq!( &headers["Accept"], "text/html" );
290    //     assert_eq!( &headers["X-Custom-Foo"], "bar" );
291    // }
292
293    let req = Request::builder()
294        .version(Version::Http2)
295        .method("GET")
296        .url("/")
297        .header(":scheme", "http")
298        .header(":authority", "www.example.com");
299    {
300        // let headers = req.headers_mut().unwrap();
301        // headers["AAAA"] = HeaderValue::Stand("ok");
302        // let xx = &headers["Accept"];
303        // let aaa = &headers["AAAA"];
304        // println!("xxx = {:?}", xx);
305        // println!("aaa = {:?}", aaa);
306
307        // for value in headers.iter() {
308        //     println!("____={:?}", value.0);
309        //     println!("____={:?}", value.1);
310        // }
311        // assert_eq!( &headers["Accept"], "text/html" );
312        // assert_eq!( &headers["X-Custom-Foo"], "bar" );
313    }
314
315    let _rrr = req.body(()).unwrap();
316
317    // let data = rrr.http2data().unwrap();
318
319    // println!("req.httpdata() = {:?}", hex_debug_print(&data));
320
321    // let mut decode = Decoder::new();
322    // let mut buf = BinaryMut::from(data);
323    // let result = decode.decode_with_cb(&mut buf, |n, v| {
324    //     println!("n = {:?}, v = {}", n, v);
325    // });
326
327    // let mut index = Arc::new(HeaderIndex::new());
328    // Arc::get_mut(&mut index).map(|v| {
329    //     v.add_header(
330    //         HeaderName::from_static("aaa"),
331    //         HeaderValue::from_static("aa"),
332    //     );
333    // });
334
335    // let xx = Arc::get_mut(&mut index);
336    // println!("========={:?}", xx);
337    // let xx111 = Arc::get_mut(&mut index);
338    // println!("========={:?}", xx111);
339    // // rrr.extensions_mut().insert(index);
340    // // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
341    // // println!("========={:?}", new);
342
343    // // if true {
344    // //     return;
345    // // }
346
347    // let u = url::Builder::new()
348    //     .scheme("https")
349    //     .domain("www.baidu.com")
350    //     .build()
351    //     .unwrap();
352    // println!("u = {}", u);
353
354    // let response = Response::builder()
355    //     .header("Accept", "text/html")
356    //     .header("X-Custom-Foo", "bar")
357    //     .body("my is web")
358    //     .unwrap();
359
360    // println!(
361    //     "ssssssssssss {}",
362    //     String::from_utf8_lossy(&response.httpdata().unwrap())
363    // );
364
365    let mut xx = HashMap::<(u32, u8), u8>::new();
366    xx.insert((48, 5), 6);
367
368    // xx.get(&b"xx");
369
370    println!("aaa {:?}", xx.get(&(48, 5)));
371    // let response = url::Builder::
372}
Source§

impl<T> Request<T>
where T: Serialize,

Source

pub fn is_http2(&self) -> bool

查看请求是否是http2

Source

pub fn set_url(&mut self, url: Url)

Source

pub fn parts(&self) -> &Parts

返回parts信息

Source

pub fn parts_mut(&mut self) -> &mut Parts

返回parts信息

Source

pub fn method(&self) -> &Method

Source

pub fn set_method(&mut self, method: Method)

Source

pub fn version(&self) -> Version

Source

pub fn set_version(&mut self, version: Version)

Source

pub fn path(&self) -> &String

Source

pub fn set_path(&mut self, path: String)

Source

pub fn scheme(&self) -> &Scheme

Source

pub fn set_scheme(&mut self, scheme: Scheme)

Source

pub fn headers(&self) -> &HeaderMap

Examples found in repository?
examples/demo.rs (line 133)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Examples found in repository?
examples/demo.rs (line 132)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn headers_body(&mut self) -> (&HeaderMap, &T)

Source

pub fn headers_body_mut(&mut self) -> (&mut HeaderMap, &mut T)

Source

pub fn url(&self) -> &Url

Source

pub fn url_mut(&mut self) -> &mut Url

Source

pub fn get_host(&self) -> Option<String>

Examples found in repository?
examples/demo.rs (line 160)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn get_referer(&self) -> Option<String>

Source

pub fn get_user_agent(&self) -> Option<String>

Source

pub fn get_connect_url(&self) -> Option<String>

返回完整的域名加上端口号信息 如wwww.baidu.com:80, wwww.google.com:443

Examples found in repository?
examples/demo.rs (line 161)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn get_body_len(&self) -> isize

获取请求的body长度, 如果为0则表示不存在长度信息, 直到收到关闭信息则表示结束, http/1.1为关闭链接, http/2则是end_stream

Examples found in repository?
examples/demo.rs (line 159)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn get_authority(&self) -> String

获取请求的authority

Source

pub fn get_scheme(&self) -> String

获取请求的scheme

Source

pub fn is_keep_alive(&self) -> bool

是否保持心跳活跃

Source

pub fn is_partial(&self) -> bool

Examples found in repository?
examples/demo.rs (line 158)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn is_complete(&self) -> bool

Examples found in repository?
examples/demo.rs (line 188)
179fn main() {
180    let mut req = crate::Request::new();
181    let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
182    assert!(ret.err().unwrap().is_partial());
183
184    let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
185    let ret = req.parse(buf).unwrap();
186
187    assert!(ret == buf.len());
188    assert!(req.is_complete());
189
190    debug_request_parse();
191    // let mut binmut = BinaryMut::new();
192    // "aaa".serialize1(&mut binmut);
193
194    // let bin = Binary::new();
195    // let p = Pay::Data(bin);
196    // println!("bbb = {:?}", p);
197    // debug_request_parse_full_http2();
198    // debug_request_parse_http2();
199
200    //  let req = request::Builder::new()
201    //      .method("POST")
202    //      .body(())
203    //      .unwrap();
204
205    // debug_request_parse();
206    // let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
207    // let mut b = Binary::from(v);
208    // {
209    //     b.get_next();
210    //     let c = b.clone_slice();
211    //     drop(c);
212    //     b.get_next();
213    //     let d = b.clone_slice();
214    //     drop(d);
215    // }
216    // drop(b);
217    println!("finish");
218    // let len = v.len();
219    // let raw = Box::into_raw(v) as *mut u8;
220
221    // // Layout::from_size_align(cap, 1);
222
223    // let value = unsafe { Vec::from_raw_parts(raw, len, len) };
224    // println!("value = {:?}", value);
225
226    if true {
227        return;
228    }
229
230    // let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
231    // // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
232    // // println!("result = {:?}", request);
233    // // println!("is_partial = {}", request.is_partial());
234
235    // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
236    // println!("result = {:?}", request);
237    // println!("is_partial = {}", request.is_partial());
238    // println!("body len = {}", request.get_body_len());
239
240    let url: Result<Url, webparse::WebError> =
241        Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
242    println!("value = {:?}", url);
243    println!("value = {}", url.ok().unwrap());
244
245    let url = Url::try_from("/path?qqq=222");
246    println!("value = {:?}", url);
247    println!("value = {}", url.ok().unwrap());
248
249    println!("decode = {:?}", Url::url_decode("%48%211111"));
250    println!("decode = {:?}", Url::url_decode("%48%21111%1"));
251    println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
252    let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
253    println!("value = {}", value);
254
255    // // let value = url::Url::parse("/path");
256    // let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
257    // println!("result = {:?}", request);
258    // println!("is_partial = {}", request.is_partial());
259    // println!("body len = {}", request.get_body_len());
260    // println!("host len = {:?}", request.get_host());
261    // println!("host len = {:?}", request.get_connect_url());
262
263    // let mut buffer = Buffer::new();
264    // request.serialize(&mut buffer).expect("ok");
265    // println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
266
267    // println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
268
269    // let mut req = Request::builder();
270    // assert_eq!(req.url_ref().unwrap(), "/" );
271    // req = req.url("https://www.rust-lang.org/");
272    // assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
273
274    // let mut req = Request::builder().version(Version::Http2).method("GET")
275    //     .header("Accept", "text/html")
276    //     .header("X-Custom-Foo", "bar");
277    // {
278    //     let headers = req.headers_mut().unwrap();
279    //     headers["AAAA"] = HeaderValue::Stand("ok");
280    //     let xx = &headers["Accept"];
281    //     let aaa = &headers["AAAA"];
282    //     println!("xxx = {:?}", xx);
283    //     println!("aaa = {:?}", aaa);
284
285    //     for value in headers.iter() {
286    //         println!("____={:?}", value.0);
287    //         println!("____={:?}", value.1);
288    //     }
289    //     assert_eq!( &headers["Accept"], "text/html" );
290    //     assert_eq!( &headers["X-Custom-Foo"], "bar" );
291    // }
292
293    let req = Request::builder()
294        .version(Version::Http2)
295        .method("GET")
296        .url("/")
297        .header(":scheme", "http")
298        .header(":authority", "www.example.com");
299    {
300        // let headers = req.headers_mut().unwrap();
301        // headers["AAAA"] = HeaderValue::Stand("ok");
302        // let xx = &headers["Accept"];
303        // let aaa = &headers["AAAA"];
304        // println!("xxx = {:?}", xx);
305        // println!("aaa = {:?}", aaa);
306
307        // for value in headers.iter() {
308        //     println!("____={:?}", value.0);
309        //     println!("____={:?}", value.1);
310        // }
311        // assert_eq!( &headers["Accept"], "text/html" );
312        // assert_eq!( &headers["X-Custom-Foo"], "bar" );
313    }
314
315    let _rrr = req.body(()).unwrap();
316
317    // let data = rrr.http2data().unwrap();
318
319    // println!("req.httpdata() = {:?}", hex_debug_print(&data));
320
321    // let mut decode = Decoder::new();
322    // let mut buf = BinaryMut::from(data);
323    // let result = decode.decode_with_cb(&mut buf, |n, v| {
324    //     println!("n = {:?}, v = {}", n, v);
325    // });
326
327    // let mut index = Arc::new(HeaderIndex::new());
328    // Arc::get_mut(&mut index).map(|v| {
329    //     v.add_header(
330    //         HeaderName::from_static("aaa"),
331    //         HeaderValue::from_static("aa"),
332    //     );
333    // });
334
335    // let xx = Arc::get_mut(&mut index);
336    // println!("========={:?}", xx);
337    // let xx111 = Arc::get_mut(&mut index);
338    // println!("========={:?}", xx111);
339    // // rrr.extensions_mut().insert(index);
340    // // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
341    // // println!("========={:?}", new);
342
343    // // if true {
344    // //     return;
345    // // }
346
347    // let u = url::Builder::new()
348    //     .scheme("https")
349    //     .domain("www.baidu.com")
350    //     .build()
351    //     .unwrap();
352    // println!("u = {}", u);
353
354    // let response = Response::builder()
355    //     .header("Accept", "text/html")
356    //     .header("X-Custom-Foo", "bar")
357    //     .body("my is web")
358    //     .unwrap();
359
360    // println!(
361    //     "ssssssssssss {}",
362    //     String::from_utf8_lossy(&response.httpdata().unwrap())
363    // );
364
365    let mut xx = HashMap::<(u32, u8), u8>::new();
366    xx.insert((48, 5), 6);
367
368    // xx.get(&b"xx");
369
370    println!("aaa {:?}", xx.get(&(48, 5)));
371    // let response = url::Builder::
372}
Source

pub fn into<B: Serialize>(self, body: B) -> (Request<B>, T)

Source

pub fn into_type<B: From<T> + Serialize>(self) -> Request<B>

Source

pub fn parse_buffer<B: Bt>(&mut self, buffer: &mut B) -> WebResult<usize>

Source

pub fn parse(&mut self, buf: &[u8]) -> WebResult<usize>

Examples found in repository?
examples/demo.rs (line 81)
70fn debug_request_parse_full_http2() {
71    let http2: Vec<u8> = vec![
72        80, 82, 73, 32, 42, 32, 72, 84, 84, 80, 47, 50, 46, 48, 13, 10, 13, 10, 83, 77, 13, 10, 13,
73        10, 0, 0, 18, 4, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 100, 0, 4, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
74        0, 4, 8, 0, 0, 0, 0, 0, 1, 255, 0, 1, 0, 0, 55, 1, 5, 0, 0, 0, 1, 131, 132, 134, 65, 143,
75        11, 226, 92, 46, 60, 184, 93, 125, 112, 178, 205, 199, 128, 240, 63, 122, 136, 37, 182, 80,
76        195, 171, 186, 210, 224, 83, 3, 42, 47, 42, 64, 136, 37, 168, 73, 233, 91, 169, 125, 127,
77        137, 37, 168, 73, 233, 91, 184, 232, 180, 191, 0, 0, 25, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78        0, 0, 1, 83, 69, 84, 84, 73, 78, 71, 83, 32, 101, 120, 112, 101, 99, 116, 101, 100,
79    ];
80    let mut req = Request::new();
81    let _size = req.parse(&http2).unwrap();
82    println!("req = {:?}", req);
83}
84
85// fn debug_request_parse_http2() {
86//     let mut decode = Decoder::new();
87//     let _http2 = vec![
88//         0x82, 0x86, 0x84, 0x41, 0x8c, 0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90,
89//         0xf4, 0xff,
90//     ];
91//     let http2 = hexstr_to_vec("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ");
92
93//     let mut buf = BinaryMut::from(http2);
94
95//     let _result = decode.decode_with_cb(&mut buf, |n, v| {
96//         println!("n = {:?}, v = {:?}", n, v);
97//     });
98//     // println!("result = {:?}", result);
99//     // let http2 = vec![
100//     //     0x82, 0x86, 0x84, 0xbe, 0x58, 0x08, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65,
101//     // ];
102//     // let http2 = hexstr_to_vec("8286 84be 5808 6e6f 2d63 6163 6865");
103
104//     // let mut buf = BinaryMut::from(http2);
105//     // let result = decode.decode_with_cb(&mut buf, |n, v| {
106//     //     println!("n = {:?}, v = {:?}", n, v);
107//     // });
108//     // println!("result = {:?}", result);
109
110//     // {
111//     //     //         8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 | ....@.%.I.[.}..%
112//     //     //          a849 e95b b8e8 b4bf
113//     //     let http2 = vec![
114//     //         0x82, 0x87, 0x85, 0xbf, 0x40, 0x88, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xa9, 0x7d, 0x7f,
115//     //         0x89, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xb8, 0xe8, 0xb4, 0xbf,
116//     //     ];
117//     //     let http2 = hexstr_to_vec(
118//     //         "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65",
119//     //     );
120
121//     //     let mut buf = BinaryMut::from(http2);
122
123//     //     let result = decode.decode_with_cb(&mut buf, |n, v| {
124//     //         println!("n = {:?}, v = {:?}", n, v);
125//     //     });
126//     //     println!("result = {:?}", result);
127//     // }
128// }
129
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
178
179fn main() {
180    let mut req = crate::Request::new();
181    let ret = req.parse(b"GET / HTTP/1.1\r\nHost: 127.0.0.1\r");
182    assert!(ret.err().unwrap().is_partial());
183
184    let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n";
185    let ret = req.parse(buf).unwrap();
186
187    assert!(ret == buf.len());
188    assert!(req.is_complete());
189
190    debug_request_parse();
191    // let mut binmut = BinaryMut::new();
192    // "aaa".serialize1(&mut binmut);
193
194    // let bin = Binary::new();
195    // let p = Pay::Data(bin);
196    // println!("bbb = {:?}", p);
197    // debug_request_parse_full_http2();
198    // debug_request_parse_http2();
199
200    //  let req = request::Builder::new()
201    //      .method("POST")
202    //      .body(())
203    //      .unwrap();
204
205    // debug_request_parse();
206    // let v = vec![1u8, 2, 3, 5, 7, 9, 10].into_boxed_slice();
207    // let mut b = Binary::from(v);
208    // {
209    //     b.get_next();
210    //     let c = b.clone_slice();
211    //     drop(c);
212    //     b.get_next();
213    //     let d = b.clone_slice();
214    //     drop(d);
215    // }
216    // drop(b);
217    println!("finish");
218    // let len = v.len();
219    // let raw = Box::into_raw(v) as *mut u8;
220
221    // // Layout::from_size_align(cap, 1);
222
223    // let value = unsafe { Vec::from_raw_parts(raw, len, len) };
224    // println!("value = {:?}", value);
225
226    if true {
227        return;
228    }
229
230    // let mut request = webparse::Request::builder().body("What is this".to_string()).unwrap();
231    // // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n").unwrap();
232    // // println!("result = {:?}", request);
233    // // println!("is_partial = {}", request.is_partial());
234
235    // let _result = request.parse(b"GET /index.html HTTP/1.1\r\nHost: example.domain1\r\ncontent-length: 1111\r\n");
236    // println!("result = {:?}", request);
237    // println!("is_partial = {}", request.is_partial());
238    // println!("body len = {}", request.get_body_len());
239
240    let url: Result<Url, webparse::WebError> =
241        Url::try_from("https://%4811:!%2011@www.baidu.com:88/path?aaa=222");
242    println!("value = {:?}", url);
243    println!("value = {}", url.ok().unwrap());
244
245    let url = Url::try_from("/path?qqq=222");
246    println!("value = {:?}", url);
247    println!("value = {}", url.ok().unwrap());
248
249    println!("decode = {:?}", Url::url_decode("%48%211111"));
250    println!("decode = {:?}", Url::url_decode("%48%21111%1"));
251    println!("decode = {:?}", Url::url_decode("%48%21111%4j"));
252    let value = Url::try_from("https://11:11@www.baidu.com/path").unwrap();
253    println!("value = {}", value);
254
255    // // let value = url::Url::parse("/path");
256    // let _result = request.parse(b"GET http://www.baidu.com/ HTTP/1.1\r\nHost: www.baidu.com\r\nUser-Agent: curl/7.74.0\r\nAccept: */*\r\nProxy-Connection: Keep-Alive\r\n\r\n");
257    // println!("result = {:?}", request);
258    // println!("is_partial = {}", request.is_partial());
259    // println!("body len = {}", request.get_body_len());
260    // println!("host len = {:?}", request.get_host());
261    // println!("host len = {:?}", request.get_connect_url());
262
263    // let mut buffer = Buffer::new();
264    // request.serialize(&mut buffer).expect("ok");
265    // println!("aaaaaaaaaaaaaaa {}", String::from_utf8_lossy(buffer.get_write_data()));
266
267    // println!("aaaaaaaaaaaaaaa11111 {}", String::from_utf8_lossy(&request.httpdata().unwrap()));
268
269    // let mut req = Request::builder();
270    // assert_eq!(req.url_ref().unwrap(), "/" );
271    // req = req.url("https://www.rust-lang.org/");
272    // assert_eq!(req.url_ref().unwrap(), "https://www.rust-lang.org/" );
273
274    // let mut req = Request::builder().version(Version::Http2).method("GET")
275    //     .header("Accept", "text/html")
276    //     .header("X-Custom-Foo", "bar");
277    // {
278    //     let headers = req.headers_mut().unwrap();
279    //     headers["AAAA"] = HeaderValue::Stand("ok");
280    //     let xx = &headers["Accept"];
281    //     let aaa = &headers["AAAA"];
282    //     println!("xxx = {:?}", xx);
283    //     println!("aaa = {:?}", aaa);
284
285    //     for value in headers.iter() {
286    //         println!("____={:?}", value.0);
287    //         println!("____={:?}", value.1);
288    //     }
289    //     assert_eq!( &headers["Accept"], "text/html" );
290    //     assert_eq!( &headers["X-Custom-Foo"], "bar" );
291    // }
292
293    let req = Request::builder()
294        .version(Version::Http2)
295        .method("GET")
296        .url("/")
297        .header(":scheme", "http")
298        .header(":authority", "www.example.com");
299    {
300        // let headers = req.headers_mut().unwrap();
301        // headers["AAAA"] = HeaderValue::Stand("ok");
302        // let xx = &headers["Accept"];
303        // let aaa = &headers["AAAA"];
304        // println!("xxx = {:?}", xx);
305        // println!("aaa = {:?}", aaa);
306
307        // for value in headers.iter() {
308        //     println!("____={:?}", value.0);
309        //     println!("____={:?}", value.1);
310        // }
311        // assert_eq!( &headers["Accept"], "text/html" );
312        // assert_eq!( &headers["X-Custom-Foo"], "bar" );
313    }
314
315    let _rrr = req.body(()).unwrap();
316
317    // let data = rrr.http2data().unwrap();
318
319    // println!("req.httpdata() = {:?}", hex_debug_print(&data));
320
321    // let mut decode = Decoder::new();
322    // let mut buf = BinaryMut::from(data);
323    // let result = decode.decode_with_cb(&mut buf, |n, v| {
324    //     println!("n = {:?}, v = {}", n, v);
325    // });
326
327    // let mut index = Arc::new(HeaderIndex::new());
328    // Arc::get_mut(&mut index).map(|v| {
329    //     v.add_header(
330    //         HeaderName::from_static("aaa"),
331    //         HeaderValue::from_static("aa"),
332    //     );
333    // });
334
335    // let xx = Arc::get_mut(&mut index);
336    // println!("========={:?}", xx);
337    // let xx111 = Arc::get_mut(&mut index);
338    // println!("========={:?}", xx111);
339    // // rrr.extensions_mut().insert(index);
340    // // let new = rrr.extensions_mut().get_mut::<Arc<HeaderIndex>>();
341    // // println!("========={:?}", new);
342
343    // // if true {
344    // //     return;
345    // // }
346
347    // let u = url::Builder::new()
348    //     .scheme("https")
349    //     .domain("www.baidu.com")
350    //     .build()
351    //     .unwrap();
352    // println!("u = {}", u);
353
354    // let response = Response::builder()
355    //     .header("Accept", "text/html")
356    //     .header("X-Custom-Foo", "bar")
357    //     .body("my is web")
358    //     .unwrap();
359
360    // println!(
361    //     "ssssssssssss {}",
362    //     String::from_utf8_lossy(&response.httpdata().unwrap())
363    // );
364
365    let mut xx = HashMap::<(u32, u8), u8>::new();
366    xx.insert((48, 5), 6);
367
368    // xx.get(&b"xx");
369
370    println!("aaa {:?}", xx.get(&(48, 5)));
371    // let response = url::Builder::
372}
Source

pub fn extensions(&self) -> &Extensions

Returns a reference to the associated extensions.

§Examples
use webparse::*;
let request: Request<()> = Request::default();
assert!(request.extensions().get::<i32>().is_none());
Source

pub fn extensions_mut(&mut self) -> &mut Extensions

Source

pub fn http1_data(&mut self) -> WebResult<Vec<u8>>

Examples found in repository?
examples/demo.rs (line 164)
130fn debug_request_parse() {
131    let mut request = Request::new();
132    request.headers_mut().insert("Connection", "ok");
133    let _xx = request.headers().is_keep_alive();
134    return;
135    // // let value = url::Url::parse("/path");
136    let _bytes = [
137        80, 79, 83, 84, 32, 47, 112, 111, 115, 116, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72,
138        111, 115, 116, 58, 32, 49, 57, 50, 46, 49, 54, 56, 46, 49, 55, 57, 46, 49, 51, 51, 58, 56,
139        48, 56, 48, 13, 10, 85, 115, 101, 114, 45, 65, 103, 101, 110, 116, 58, 32, 99, 117, 114,
140        108, 47, 55, 46, 55, 52, 46, 48, 13, 10, 65, 99, 99, 101, 112, 116, 58, 32, 42, 47, 42, 13,
141        10, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 85, 112, 103, 114, 97, 100,
142        101, 44, 32, 72, 84, 84, 80, 50, 45, 83, 101, 116, 116, 105, 110, 103, 115, 13, 10, 85,
143        112, 103, 114, 97, 100, 101, 58, 32, 104, 50, 99, 13, 10, 72, 84, 84, 80, 50, 45, 83, 101,
144        116, 116, 105, 110, 103, 115, 58, 32, 65, 65, 77, 65, 65, 65, 66, 107, 65, 65, 81, 67, 65,
145        65, 65, 65, 65, 65, 73, 65, 65, 65, 65, 65, 13, 10, 99, 117, 115, 116, 111, 109, 45, 107,
146        101, 121, 58, 99, 117, 115, 116, 111, 109, 45, 118, 97, 108, 117, 101, 13, 10, 67, 111,
147        110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 50, 49, 13, 10, 67, 111,
148        110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97,
149        116, 105, 111, 110, 47, 120, 45, 119, 119, 119, 45, 102, 111, 114, 109, 45, 117, 114, 108,
150        101, 110, 99, 111, 100, 101, 100, 13, 10, 13, 10, 97, 97, 48, 48, 48, 48, 48, 48, 48, 48,
151        48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
152    ];
153    let _result =
154        request.parse(b"GET //:///// HTTP/1.1\r\nHost: Upgrade, HTTP2-Settings \r\n\r\naaa");
155    // let _result = request.parse(&bytes);
156
157    println!("result = {:?}", request);
158    println!("is_partial = {}", request.is_partial());
159    println!("body len = {}", request.get_body_len());
160    println!("host len = {:?}", request.get_host());
161    println!("host len = {:?}", request.get_connect_url());
162    println!(
163        "http data = {}",
164        String::from_utf8_lossy(&request.http1_data().unwrap())
165    );
166    assert_eq!(
167        String::from_utf8_lossy(&request.http1_data().unwrap()).as_bytes(),
168        b"GET //:///// HTTP/1.1\r\nHost: \r\n\r\n"
169    );
170    let x = &request.headers()["Host"];
171    if x == &"foo" {
172        println!("111");
173    }
174    if &"foo" == x {
175        println!("111");
176    }
177}
Source

pub fn body(&self) -> &T

Source

pub fn body_mut(&mut self) -> &mut T

Source

pub fn encode_header<B: Bt + BtMut>( &mut self, buffer: &mut B, ) -> WebResult<usize>

Source

pub fn replace_clone(&mut self, body: T) -> Request<T>

Trait Implementations§

Source§

impl<T> Debug for Request<T>
where T: Serialize + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Request<()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Display for Request<T>
where T: Serialize + Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Request<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Request<T>

§

impl<T> Send for Request<T>
where T: Send,

§

impl<T> Sync for Request<T>
where T: Sync,

§

impl<T> Unpin for Request<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Request<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.