1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use futures::channel::mpsc;
67#[derive(Debug)]
8pub struct UnboundedSink<T> {
9 sink: mpsc::UnboundedSender<T>,
10}
1112// Manually impl clone to allow non-Clone values of T.
13// https://github.com/rust-lang/rust/issues/26925
14impl<T> Clone for UnboundedSink<T> {
15fn clone(&self) -> Self {
16Self { sink: self.sink.clone() }
17 }
18}
1920impl<T> UnboundedSink<T> {
21pub fn new(sink: mpsc::UnboundedSender<T>) -> Self {
22 UnboundedSink { sink }
23 }
2425pub fn send(&self, msg: T) {
26match self.sink.unbounded_send(msg) {
27Ok(()) => {}
28Err(e) => {
29if e.is_full() {
30panic!("Did not expect an unbounded channel to be full: {:?}", e);
31 }
32// If the other side has disconnected, we can still technically function,
33 // so ignore the error.
34}
35 }
36 }
37}