Debian Codegraph @

src/transfer/buffer.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#;
3
4 use superrust-analyzer cargo nusb 0.1.13 transfer/::TransferRequestrust-analyzer cargo nusb 0.1.13 transfer/internal/TransferRequest#;
5
6 /// A buffer for requesting an IN transfer.
7 ///
8 /// A `RequestBuffer` is passed when submitting an `IN` transfer to define the
9 /// requested length and provide a buffer to receive data into. The buffer is
10 /// returned in the [`Completion`][`crate::transfer::Completion`] as a `Vec<u8>`
11 /// with the data read from the endpoint. The `Vec`'s allocation can turned back
12 /// into a `RequestBuffer` to re-use it for another transfer.
13 ///
14 /// You can think of a `RequestBuffer` as a `Vec` with uninitialized contents.
15 pub struct RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
16 pub(craterust-analyzer cargo nusb 0.1.13 crate/) bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#buf.: *mut u8,
17 pub(craterust-analyzer cargo nusb 0.1.13 crate/) capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#capacity.: usize,
18 pub(craterust-analyzer cargo nusb 0.1.13 crate/) requestedrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#requested.: usize,
19 }
20
21 impl RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
22 /// Create a `RequestBuffer` of the specified size.
23 pub fn newrust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[RequestBuffer]new().(len: usize) -> RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
24 let mut v = ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(len));
25 RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
26 bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#buf.: v.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(),
27 capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#capacity.: v.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(),
28 requestedrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#requested.: len,
29 }
30 }
31
32 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn into_vecrust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[RequestBuffer]into_vec().(self) -> (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, usize) {
33 let s = ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(self);
34 let v = unsafe { Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(s.bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#buf., 0, s.capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#capacity.) };
35 (v, s.requestedrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#requested.)
36 }
37
38 /// Create a `RequestBuffer` by re-using the allocation of a `Vec`.
39 pub fn reuserust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[RequestBuffer]reuse().(v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, len: usize) -> RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
40 let mut v = ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(v);
41 v.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().();
42 v.reserve_exactrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve_exact().(len);
43 RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
44 bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#buf.: v.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(),
45 capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#capacity.: v.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(),
46 requestedrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#requested.: len,
47 }
48 }
49 }
50
51 unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {}
52 unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {}
53
54 impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
55 fn droprust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[RequestBuffer][Drop]drop().(&mut self) {
56 unsafe { droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(self.bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#buf., 0, self.capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#capacity.)) }
57 }
58 }
59
60 impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
61 fn fmtrust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[RequestBuffer][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
62 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("RequestBuffer")
63 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("requested", &self.requestedrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#requested.)
64 .finish_non_exhaustiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish_non_exhaustive().()
65 }
66 }
67
68 impl TransferRequestrust-analyzer cargo nusb 0.1.13 transfer/internal/TransferRequest# for RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer# {
69 type Responserust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[RequestBuffer][TransferRequest]Response# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>;
70 }
71
72 /// Returned buffer and actual length for a completed OUT transfer.
73 ///
74 /// When an `OUT` transfer completes, a `ResponseBuffer` is returned in the
75 /// `Completion`. The [`actual_length`][`ResponseBuffer::actual_length`] tells
76 /// you how many bytes were successfully sent, which may be useful in the case
77 /// of a partially-completed transfer.
78 ///
79 /// The `ResponseBuffer` can be turned into an empty `Vec` to re-use the allocation
80 /// for another transfer, or dropped to free the memory.
81 pub struct ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {
82 pub(craterust-analyzer cargo nusb 0.1.13 crate/) bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#buf.: *mut u8,
83 pub(craterust-analyzer cargo nusb 0.1.13 crate/) capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#capacity.: usize,
84 pub(craterust-analyzer cargo nusb 0.1.13 crate/) transferredrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#transferred.: usize,
85 }
86
87 impl ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {
88 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn from_vecrust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[ResponseBuffer]from_vec().(v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, transferred: usize) -> ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {
89 let mut v = ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(v);
90 ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {
91 bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#buf.: v.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().(),
92 capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#capacity.: v.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(),
93 transferredrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#transferred.,
94 }
95 }
96
97 /// Get the number of bytes successfully transferred.
98 pub fn actual_lengthrust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[ResponseBuffer]actual_length().(&self) -> usize {
99 self.transferredrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#transferred.
100 }
101
102 /// Extract the buffer as an empty `Vec` to re-use in another transfer.
103 pub fn reuserust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[ResponseBuffer]reuse().(self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
104 let s = ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(self);
105 unsafe { Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(s.bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#buf., 0, s.capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#capacity.) }
106 }
107 }
108
109 impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {
110 fn fmtrust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[ResponseBuffer][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
111 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("ResponseBuffer")
112 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("transferred", &self.transferredrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#transferred.)
113 .finish_non_exhaustiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish_non_exhaustive().()
114 }
115 }
116
117 unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {}
118 unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {}
119
120 impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer# {
121 fn droprust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[ResponseBuffer][Drop]drop().(&mut self) {
122 unsafe { droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(self.bufrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#buf., 0, self.capacityrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#capacity.)) }
123 }
124 }
125
126 impl TransferRequestrust-analyzer cargo nusb 0.1.13 transfer/internal/TransferRequest# for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
127 type Responserust-analyzer cargo nusb 0.1.13 transfer/buffer/impl#[`Vec<u8>`][TransferRequest]Response# = ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#;
128 }