nt_string/
traits.rs

1// Copyright 2023 Colin Finck <colin@reactos.org>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3//
4//! Additional traits provided by this crate.
5
6/// Fallible variant of the [`Extend`] trait
7pub trait TryExtend<T> {
8    /// The type returned in the event of an error.
9    type Error;
10
11    /// Tries to extends a collection with the contents of an iterator.
12    fn try_extend<I: IntoIterator<Item = T>>(&mut self, iter: I) -> Result<(), Self::Error>;
13
14    /// Tries to extend a collection with exactly one element.
15    fn try_extend_one(&mut self, item: T) -> Result<(), Self::Error> {
16        self.try_extend(Some(item))
17    }
18}