|
661 | 661 | <a href="#660" id="660">660</a> |
662 | 662 | <a href="#661" id="661">661</a> |
663 | 663 | <a href="#662" id="662">662</a> |
664 | | -<a href="#663" id="663">663</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{boxed::Box, string::String, sync::Arc}; |
| 664 | +<a href="#663" id="663">663</a> |
| 665 | +<a href="#664" id="664">664</a> |
| 666 | +<a href="#665" id="665">665</a> |
| 667 | +<a href="#666" id="666">666</a> |
| 668 | +<a href="#667" id="667">667</a> |
| 669 | +<a href="#668" id="668">668</a> |
| 670 | +<a href="#669" id="669">669</a> |
| 671 | +<a href="#670" id="670">670</a> |
| 672 | +<a href="#671" id="671">671</a> |
| 673 | +<a href="#672" id="672">672</a> |
| 674 | +<a href="#673" id="673">673</a> |
| 675 | +<a href="#674" id="674">674</a> |
| 676 | +<a href="#675" id="675">675</a> |
| 677 | +<a href="#676" id="676">676</a> |
| 678 | +<a href="#677" id="677">677</a> |
| 679 | +<a href="#678" id="678">678</a> |
| 680 | +<a href="#679" id="679">679</a> |
| 681 | +<a href="#680" id="680">680</a> |
| 682 | +<a href="#681" id="681">681</a> |
| 683 | +<a href="#682" id="682">682</a> |
| 684 | +<a href="#683" id="683">683</a> |
| 685 | +<a href="#684" id="684">684</a> |
| 686 | +<a href="#685" id="685">685</a> |
| 687 | +<a href="#686" id="686">686</a> |
| 688 | +<a href="#687" id="687">687</a> |
| 689 | +<a href="#688" id="688">688</a> |
| 690 | +<a href="#689" id="689">689</a> |
| 691 | +<a href="#690" id="690">690</a> |
| 692 | +<a href="#691" id="691">691</a> |
| 693 | +<a href="#692" id="692">692</a> |
| 694 | +<a href="#693" id="693">693</a> |
| 695 | +<a href="#694" id="694">694</a> |
| 696 | +<a href="#695" id="695">695</a> |
| 697 | +<a href="#696" id="696">696</a> |
| 698 | +<a href="#697" id="697">697</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{boxed::Box, string::String, sync::Arc}; |
665 | 699 | <span class="kw">use </span>core::{error, fmt, future::Future}; |
666 | 700 |
|
667 | 701 | <span class="kw">use </span>parking_lot::Mutex; |
|
705 | 739 | } |
706 | 740 | } |
707 | 741 |
|
| 742 | + <span class="doccomment">/// Constructs a stub device for testing using [`Backend::Noop`]. |
| 743 | + /// |
| 744 | + /// This is a convenience function which avoids the configuration, `async`, and fallibility |
| 745 | + /// aspects of constructing a device through `Instance`. |
| 746 | + </span><span class="attr">#[cfg(feature = <span class="string">"noop"</span>)] |
| 747 | + </span><span class="kw">pub fn </span>noop(desc: <span class="kw-2">&</span>DeviceDescriptor<<span class="lifetime">'_</span>>) -> (Device, Queue) { |
| 748 | + <span class="kw">use </span>core::future::Future <span class="kw">as _</span>; |
| 749 | + <span class="kw">use </span>core::pin::pin; |
| 750 | + <span class="kw">use </span>core::task; |
| 751 | + <span class="kw">let </span>ctx = <span class="kw-2">&mut </span>task::Context::from_waker(task::Waker::noop()); |
| 752 | + |
| 753 | + <span class="kw">let </span>instance = Instance::new(<span class="kw-2">&</span>InstanceDescriptor { |
| 754 | + backends: Backends::NOOP, |
| 755 | + backend_options: BackendOptions { |
| 756 | + noop: NoopBackendOptions { enable: <span class="bool-val">true </span>}, |
| 757 | + ..Default::default() |
| 758 | + }, |
| 759 | + ..Default::default() |
| 760 | + }); |
| 761 | + |
| 762 | + <span class="comment">// Both of these futures are trivial and should complete instantaneously, |
| 763 | + // so we do not need an executor and can just poll them once. |
| 764 | + </span><span class="kw">let </span>task::Poll::Ready(<span class="prelude-val">Ok</span>(adapter)) = |
| 765 | + <span class="macro">pin!</span>(instance.request_adapter(<span class="kw-2">&</span>RequestAdapterOptions::default())).poll(ctx) |
| 766 | + <span class="kw">else </span>{ |
| 767 | + <span class="macro">unreachable!</span>() |
| 768 | + }; |
| 769 | + <span class="kw">let </span>task::Poll::Ready(<span class="prelude-val">Ok</span>(device_and_queue)) = <span class="macro">pin!</span>(adapter.request_device(desc)).poll(ctx) |
| 770 | + <span class="kw">else </span>{ |
| 771 | + <span class="macro">unreachable!</span>() |
| 772 | + }; |
| 773 | + device_and_queue |
| 774 | + } |
| 775 | + |
708 | 776 | <span class="doccomment">/// Check for resource cleanups and mapping callbacks. Will block if [`PollType::Wait`] is passed. |
709 | 777 | /// |
710 | 778 | /// Return `true` if the queue is empty, or `false` if there are more queue |
|
0 commit comments